フラグメント クラスがあります。そのクラスでは、グリッドビュー アイテムをクリックして別のフラグメント クラスに移動できます。戻るボタンを押して元のクラスに戻るにはどうすればよいですか。
例 :TheaterFragment クラス --->Gridview ---->gridview 内の項目をクリック ---> TheaterDetailsFragment
TheaterDetailsFragment から戻るボタンを押して、再び TheaterFragment クラスに戻りたいです。
前もって感謝します
TheaterFragment クラス
package com.fortuna.cinemalk;
import java.util.ArrayList;
import android.app.Activity;
import android.app.FragmentManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.content.Intent;
import android.widget.AdapterView;
import com.fortuna.cinemalk.adapter.LazyAdapter;
import com.fortuna.cinemalk.model.BaseElement;
import com.fortuna.cinemalk.service.CommonVariable;
import com.fortuna.cinemalk.service.JSONServices;
import com.fortuna.cinemalk.util.Element;
public class TheaterFragment extends Fragment {
private GridView gridView;
private ArrayList<BaseElement> filmTheater;
private LazyAdapter adapter;
private Activity activity;
private CommonVariable commonVariable;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.theater_fragment, container,
false);
activity = this.getActivity();
commonVariable = (CommonVariable) activity.getApplication();
gridView = (GridView) view.findViewById(R.id.gridView1);
gridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
android.support.v4.app.Fragment detail = new TheaterDetailFragment();
android.support.v4.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
}
});
/* FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
Fragment profileFragment = new MovieDetailFragment();//the fragment you want to show
profileFragment.setArguments(bundle);
fragmentTransaction.replace(R.id.shortfilm, profileFragment);//R.id.content_frame is the layout you want to replace
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit(); */
new BackGround().execute();
return view;
}
public class BackGround extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
filmTheater = JSONServices.getTheater();
return null;
}
@Override
/* check again */
protected void onPostExecute(Void result) {
commonVariable.setTheater(filmTheater);
adapter = new LazyAdapter(filmTheater, activity,
Element.THEATER_LIST.getType());
gridView.setAdapter(adapter);
super.onPostExecute(result);
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
}
}
TheaterDetailFragment
package com.fortuna.cinemalk;
import com.fortuna.cinemalk.service.CommonVariable;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
public class TheaterDetailFragment extends Fragment {
private Activity activity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.filmhall, container,
false);
activity = this.getActivity();
return view;
}
}