フラグメントに関するSOに関する質問をかなり多く見ましたが、自分がやりたいことが可能かどうかはまだわかりません。さらに、デザインパターンに欠陥があり、全体を作り直す必要がある場合はさらにそうです。処理する。基本的に、これまでに尋ねられたほとんどの質問と同様に、NavigationTabsを備えたActionBarがあり(ActionBarSherlockを使用)、各タブ内にFragementActivityがあり、行が選択されるとFragmentActivitiesが新しいFragmentsをプッシュします(再作成しようとしています) AndroidのiOSプロジェクトであり、特定の情報にドリルダウンできるいくつかのタブを備えた基本的なナビゲーションベースのアプリです)。電話の戻るボタンをクリックすると、前のフラグメントがロードされますが、フラグメントはそれ自体を再作成し(したがって、ビューごとにWebサービスが再度呼び出されます)、情報がないため、これは必要ありません。後方に移動すると、前のビューで変更されます。つまり、基本的に私が理解したいのは、電話の戻るボタンを押すと、前のフラグメントがすでに作成された前のアイテムでプルアップされるように、フラグメントを設定する方法です。以下は私の現在のコードです:
//This is from my FragmentActivity Class that contains the ActionBar and Tab Selection Control
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
int selectedTab = tab.getPosition();
if (selectedTab == 0) {
SalesMainScreen salesScreen = new SalesMainScreen();
ft.replace(R.id.content, salesScreen);
}
else if (selectedTab == 1) {
ClientMainScreen clientScreen = new ClientMainScreen();
ft.replace(R.id.content, clientScreen);
}.....
//This is within the ClientMainScreen Fragment Class, which handles moving to the Detail Fragment
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Do something if Row is clicked
try{
String selectedClientName = clientObject.getString("ClientName");
String selectedClientID = clientObject.getString("ClientID");
String selectedValue = clientObject.getString("ClientValue");
transaction = getFragmentManager().beginTransaction();
ClientDetailScreen detailScreen = new ClientDetailScreen();
detailScreen.clientID = selectedClientID;
detailScreen.clientName = selectedClientName;
detailScreen.clientValue = selectedValue;
int currentID = ((ViewGroup)getView().getParent()).getId();
transaction.replace(currentID,detailScreen);
transaction.addToBackStack(null);
transaction.commit();
}
catch (Exception e) {
e.printStackTrace();
}
}
});....
//And then this is the Client Detail Fragment, with the method being called to Call the Web Service and create thew (since what is displayed on this screen is dependent on what is found in the Web Service
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved) {
return inflater.inflate(R.layout.clientdetailscreen, group, false);
}
@Override
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Setup Preferences File Link
this.preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//initialize the table object
mainTable = (TableLayout)getActivity().findViewById(R.id.mainTable);
//setup the detail table
setupRelatedClientSection();
}
クライアントの詳細画面は、クライアントのメイン画面と同じメソッドを使用してもう一度ドリルダウンできますが、その新しい画面から詳細画面に戻ると、seuptRelatedClientSection()メソッドが再度呼び出されるため、フラグメント全体が再構築されます。本当に私はその画面の保存されたバージョンをプルアップしたいだけです。これは私の現在の設定で可能ですか、それとも間違った方法でアプローチしましたか?