アクティビティを拡張するメイン アクティビティがあります。Android サンプルのようなドロワー ナビゲーションを使用します。スライド メニューには、チャプターのリストがあります。クリックすると、その章のレッスンのリストがメイン アクティビティ内のコンテンツ フラグメントに表示されます。
したがって、メイン アクティビティには Fragment を拡張するクラスがあります。フラグメントのコンテンツを設定するには、次のようなメソッドがあります。
public static class contentFragment extends Fragment {
public static final String ARG_CATEGORY_NUMBER = "category_number";
public contentFragment() {
// Empty constructor required for fragment subclasses
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_content, container, false);
int i = getArguments().getInt(ARG_CATEGORY_NUMBER);
String category = getResources().getStringArray(R.array.category)[i];
((MainActivity) this.getActivity()).refreshDisplay(this.getActivity(),rootView, category);
getActivity().setTitle(category);
return rootView;
}
}
これは、listView にコスチューム アダプターを設定する refreshDisplay メソッドです。
public void refreshDisplay(Context context, View view, String category) {
List<Lesson> lessonByCategory = datasource.findByCategory(category);
ListView lv = (ListView) view.findViewById(R.id.listView);
ArrayAdapter<Lesson> adapter = new LessonListAdapter(context, lessonByCategory);
lv.setAdapter(adapter);
}
さて、onListItemClick を使用して、クリックされた項目の詳細について新しいアクティビティを開始するにはどうすればよいですか? 私は以下の方法を持っています。でもどこに置いたらいいのかわからない。refreshDisplay()の呼び出し後に Fragment を挿入すると、クリックされたアイテム (チャプター) の位置が取得されます。これは、フラグメント (私のコンテンツ フラグメント) 内のリスト内のアイテム (レッスン) ではなく、スライド メニューです。 .
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.i(LOGTAG, "onListItemClick call shod");
Lesson lesson = lessons.get(position);
Intent intent = new Intent(this, LessonDetailActivity.class);
intent.putExtra(".model.Lesson", lesson);
intent.putExtra("isStared", isStared);
startActivityForResult(intent, LESSON_DETAIL_ACTIVITY);
}
どうすればこれを修正できますか? 私が欲しいのは、章のリストを含むスライド メニューがあることです。章をクリックすると、その章に関連するレッスンが表示されます (これまでの動作)。そして、レッスンをクリックすると、そのレッスンの詳細に関する新しいアクティビティが開かれます (これは私の問題です)。