3
I have a fragment that consists of several buttons. The goal is that when I press one of these buttons the fragment
disappear and pass the value associated with that button to the activity that is in the background. What is happening is that when I press the button, the fragment does not disappear and the activity does not receive the value of the button. I am using Callback
.I have no mistake or exception.
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 I need to do?
Friend, here’s a solution to your problem: http://answall.com/questions/129013/pega-dados-de-3-fragments/129380#129380
– Emerson JS