How to get the return of this method

1

I'm using lib betterpickers , I tried to make a class to get its information in OO form, but the method does not have a return, it's a void, is there a way to get that return? / p>

public class Inflate implements CalendarDatePickerDialogFragment.OnDateSetListener{

private static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name";

public void piker(FragmentManager supportFragmentManager){
    CalendarDatePickerDialogFragment cdp = new CalendarDatePickerDialogFragment()
            .setOnDateSetListener(this);
    cdp.show(supportFragmentManager, FRAG_TAG_DATE_PICKER);
}

@Override
public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
   //Esse é o metodo
}
}

I call it in MainActivity like this:

   Inflate inflate = new Inflate();

   tes.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           inflate.piker(getSupportFragmentManager());
        }
    });

I've already tried something like onDateSet calling another method:

@Override
public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
    getData(year + "/" + monthOfYear + "/" + dayOfMonth);
}

public String getData(String data){
    return data;
}

But how would I get this return if I'm calling the piker? That's the problem, is there any way to do it? Because in this activity I have 4 places where a date must be defined, if for each one I have to do a different method the code gets huge.

Documentation: link

    
asked by anonymous 05.04.2018 / 15:06

1 answer

1

I finally got it, I changed the method and the class, it looks like this:

public class Inflate{

    private static final String FRAG_TAG_DATE_PICKER = "fragment_date_picker_name";

    public void piker(FragmentManager supportFragmentManager, final TextView textView){
        CalendarDatePickerDialogFragment cdp = new CalendarDatePickerDialogFragment();
                cdp.setOnDateSetListener(new CalendarDatePickerDialogFragment.OnDateSetListener() {
                    @Override
                    public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
                        String data = year + "/" + monthOfYear + "/" + dayOfMonth;                 //Após setar a data eu chamo o método na MainActivity para passar a data para o TextView
                        MainActivity.setData(data, textView);
                    }
                });

        cdp.show(supportFragmentManager, FRAG_TAG_DATE_PICKER);
    }
}

I call it that now:

Inflate inflate = new Inflate();
tes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
             //Agora além do FragmentManager, também passo o TextView que irá receber o valor.

               inflate.piker(getSupportFragmentManager(), tes);
            }
 });

In MainActivity, this is the method called after setting the date, it receives the date in String and the TextView that will receive the value:

public static void setData(String data, TextView textView) {
       //Então é só setar a data
        textView.setText(data);
}
    
05.04.2018 / 19:36