我有Fragment的问题。
我创建了一个main_activity并在其中添加了一个listFragment。当我点击一个listfragment项时,我打开一个新片段。我想将listfragment添加到backstack,但是当我单击后退按钮时我退出应用程序。这是我点击事件的代码:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/* if (null != mListener) {
// Notify the active callbacks interface (the activity, if the
// fragment is attached to one) that an item has been selected.
mListener.onFragmentInteraction(DummyContent.ITEMS.get(position).id);
}
*/
jsonitem item = this.listFragment.get(position);
Fragment newFragment = new descrizione_fragment();
Bundle bundle = new Bundle();
bundle.putString("evento_id",item.getTitle().toString());
newFragment.setArguments(bundle);
final android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.content_frame, newFragment);
transaction.addToBackStack(null);
transaction.commit();
//Toast.makeText(getActivity(), item.getTitle() + " Clicked!" , Toast.LENGTH_SHORT).show();
}