タブが3つあり、それぞれに適した内容をセットする方法をviewpagerで書きました。
メインのJavaが
public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return MyFragment.newInstance(position + 1); } @Override public int getCount() { return 3; } @Override public CharSequence getPageTitle(int position) { return null; } } public static class MyFragment extends Fragment { private boolean mIsRequesting = false; private static final String ARG_SECTION_NUMBER = "section_number"; public MyFragment() { } public static MyFragment newInstance(int page) { MyFragment fragment = new MyFragment(); Bundle bundle = new Bundle(); bundle.putInt("PAGE", page); fragment.setArguments(bundle); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup viewpager, Bundle savedInstanceState) { int page = getArguments().getInt("PAGE", 1); ListView listView = (ListView) inflater.inflate(R.layout.fragment_main, viewpager, false); int sectionNumber = getArguments().getInt(ARG_SECTION_NUMBER); ((appl) getActivity()).getNew(sectionNumber, true, true); NewAdapter sectionAdapter = new NewAdapter(getContext(), R.layout.listrow, appl.newList[sectionNumber]); listView.setAdapter(sectionAdapter); //ここで確認作業 loadItems(); return listView; } } private void loadItems() { この中に非同期通信完了サインを受け取るものを書く(?) }
非同期通信が
// メインスレッドで実行する処理 //バックグラウンドで行いたい処理の事前準備 @Override protected void onPostExecute(final ArrayList<NewClass> listTemp) { if (listTemp == null) { try { //進歩を伝える //ここは型引数で指定した型(void型)の可変長引数 //これが呼ばれると this.mainAct.StopProgress(0); } catch (final Exception e) { } if (this.mainAct != null) { this.mainAct.NewRefreshCallback(this.ID, null); } return; } if (appl.newList[this.ID] != null && appl.newList[this.ID].get(0).GetID().equals( listTemp.get(0).GetID())) { // 更新したが同じ場合 this.mainAct.NewRefreshCallback(this.ID, null); } else { // 更新時 // メイン画面へ戻す appl.newList[this.ID] = null; appl.newList[this.ID] = listTemp; this.mainAct.NewRefreshCallback(this.ID, this.RefreshFlg); } }
となっています。
なにやらモジュール結合が強い(?)とかで
loadItemsメソッドに非同期通信が完了した(もしくは3つのリストがセットされた)などの完了通知を書かなければいけないとからしいです。
かなり特殊で難関な状況なようらしいです。
参考にするものもありません。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー