Я пытаюсь заставить свое приложение отображать разный текст при каждом нажатии кнопки. При первом нажатии любой кнопки все работает нормально, но после слов мои текстовые представления фрагмента возвращаются к тексту по умолчанию, который я установил в XML-файле макета. Вот код кнопок, а также функция, которую я использую для загрузки данных во фрагмент:
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String title = "Bildad Kaggia";
String history = "Bildad Mwaganu Kaggia (1921 – 7 March 2005) was a Kenyan nationalist, activist, and politician. Kaggia was a member of the Mau Mau Central Committee. After independence he became a Member of Parliament. He established himself as a militant, fiery nationalist who wanted to serve the poor and landless people. Because of this he fell out irreconcilably with Jomo Kenyatta. ";
ReplaceFragment(new gridLayout(),title, history);
}
});
Я пытаюсь заставить свое приложение отображать разный текст при каждом нажатии кнопки. При первом нажатии любой кнопки все работает нормально, но после слов мои текстовые представления фрагмента возвращаются к тексту по умолчанию, который я установил в XML-файле макета. Вот код кнопок, а также функция, которую я использую для загрузки данных во фрагмент: [code]b1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {
String title = "Bildad Kaggia"; String history = "Bildad Mwaganu Kaggia (1921 – 7 March 2005) was a Kenyan nationalist, activist, and politician. Kaggia was a member of the Mau Mau Central Committee. After independence he became a Member of Parliament. He established himself as a militant, fiery nationalist who wanted to serve the poor and landless people. Because of this he fell out irreconcilably with Jomo Kenyatta. "; ReplaceFragment(new gridLayout(),title, history); } }); [/code] Вот функция replaceFragment: [code]public void ReplaceFragment (Fragment fragment, String title, String history){
fragmentManager.clearFragmentResult("history"); fragmentManager.clearFragmentResult("title"); Bundle hstry = new Bundle(); hstry.putString("hstry",history); Bundle tl = new Bundle(); tl.putString("tl",title);
fragmentManager.setFragmentResult("history",hstry); fragmentManager.setFragmentResult("title",tl); fragmentTransaction.replace(R.id.frameLayout,fragment); fragmentTransaction.commitNow(); } [/code] А вот мой фрагмент кода: [code]View view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.fragment_grid_layout, container, false);