2016-11-21 18 views
0

フラグメントがあり、その中に3つのタブホストがあります。それぞれは独自の断片です。それらをA、B、Cと呼ぶことができます。再び私はonActivityResult()などを実装している断片Cに今フラグメントがリストビューを更新しない

public boolean onOptionsItemSelected(MenuItem item) { 
     switch (item.getItemId()) { 
      case android.R.id.home: 
       onBackPressed(); 
       return true; 

      default: 
       return super.onOptionsItemSelected(item); 
     } 
    } 
    @Override 
    public void onBackPressed() { 
     super.onBackPressed(); 
     setResult(Activity.RESULT_OK); 
     finish(); 
    } 

- :私は次のように活性を閉じ活性で

public class FavCommittee extends Fragment { 
    public ArrayList<Committee> favCommitteeData = new ArrayList<>(); 

    @Nullable 
    @Override 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     favCommitteeData.clear(); 
     View rootView = inflater.inflate(R.layout.house, container, false); 
     Context cont = getActivity(); 
     final SharedPreferences pref = getContext().getSharedPreferences("MyFav", 0); 
     final SharedPreferences.Editor editor = pref.edit(); 
     Map<String,?> entries = pref.getAll(); 
     final Set<String> keys = entries.keySet(); 
     int count=0; 
     for (String key:keys) { 
      String val = pref.getString(key, null); 
      String[] store = val.split(":"); 
      if (store[0].equals("committee")) 
       count=count+1; 
     } 
     int max=0; 
     for (String k:keys){ 
      String val = pref.getString(k,null); 
      if(val!=null) 
       max=Integer.parseInt(k); 
     } 
     for (int i=0;i<max+1;i++) { 
      String val = pref.getString(Integer.toString(i), null); 
      if (val != null) { 
       String[] store = val.split(":"); 
       if (store[0].equals("committee")) { 
        count = count - 1; 
        new GetAllCommittees(getContext(), rootView).execute(store[1], Integer.toString(count)); 
       } 
      } 
     }  final ListView yourListView = (ListView) rootView.findViewById(R.id.house_listview); 
     yourListView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view,int position, long id) { 
       Committee obj = (Committee)yourListView.getItemAtPosition(position); 
       Intent intent = new Intent(FavCommittee.this.getActivity(), committee_info.class); 
       intent.putExtra("Committee",obj.getCommittee_id()); 
       startActivityForResult(intent, 1); 
      } 
     }); 

     return rootView; 
    } 

- :次いでフラグメントCIからstartactivityonresultを使用して、アクティビティを開始しますこれは:

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 
     getActivity(); 
     if(requestCode == 1 && resultCode == Activity.RESULT_OK) { 
      Log.d("Called Again",Integer.toString(favCommitteeData.size())); 
     } 

アクティビティが終了した後は、onActivityResultは呼び出されません。誰かがなぜ私を助けることができますか?

答えて

0

onActivityResultにブレークポイントを設定していないと思われます。FragmentCです。問題はこれです:私は基本的に私自身のプロジェクトで基本的に同じ状況を作り、onActivityResultが呼び出されましたが、resultCodeはActivity.RESULT_CANCELLEDです。これはあなたのアクティビティであなたのオーバーライドされたonBackPressed()にまだsuper.onBackPressed()が残っていて、その後に何が起こったかにかかわらず結果をCANCELEDに設定しているからです。

単純な答えは、あなたのアクティビティでオーバーライドされたonBackPressed()メソッドからsuper.onBackPressed()を削除することです。

+0

アクティビティはありません...フラグメントCは別のフラグメント内にあります – Anirban

+0

実際には別の方法で問題が見つかりました。私はそれに応じて私の答えを編集しました。 – LukeWaggoner

関連する問題