I have a fragment that consists of several buttons. The goal is that when I press one of these buttons the fragment
disappears and passes the value associated with that button to the activity that is in the background. What is happening is that when I click the button, the fragment does not disappear and the activity does not receive the value of the button. I'm using Callback
. I do not have any errors or exceptions.
Fragment Code:
(...)
public HoroscopeChoice() {}
/******************************
* Callback
********/
public static void setOnInfoChangedListener(OnInfoChangedListener callback) {
mCallback = callback;
}
public interface OnInfoChangedListener {
public void onInfoChanged(String horosocopo);
}
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_horoscope_choice,
container, false);
Button aquarius;
aquarius = (Button) view.findViewById(R.id.aquarius1);
final int id = view.getId();
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String horoscopo = onClick2(v.getId());
Log.d("HoroscopeChoice", "ao clicar no botao->"+horoscopo);
mCallback.onInfoChanged(horoscopo);
}
};
aquarius.setOnClickListener(onClickListener);
(...)
Activity Code:
(...)
public void onInfoChanged(String horoscopo) {
Log.d("SchedulerActivity","OnInfoChanged na Scheduler->"+horoscope);
mHoroscopeDisplay = (TextView) findViewById(R.id.dailyHoroscope4);
mHoroscopeDisplay.setText(horoscopo);
}
When I do Log.d
in the fragment I get the horoscope, already in the activity appears empty. What do I have to do?