我有一个片段,其中包含课程列表:
当我单击第一个选项以打开新视图时我想要。 我该怎么做?
下面是图片中片段的代码
public class FirstYearFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.word_list, container, false);
// Create a list of words
final ArrayList<Word> words = new ArrayList<Word>();
words.add(new Word(R.string.firstYearDirection, R.string.algevra, R.drawable.algevra));
words.add(new Word(R.string.firstYearDirection, R.string.arxaia, R.drawable.arxaia));
words.add(new Word(R.string.firstYearDirection, R.string.ekuesi, R.drawable.ekthesi));
words.add(new Word(R.string.firstYearDirection, R.string.geometria, R.drawable.geometry));
words.add(new Word(R.string.firstYearDirection, R.string.fysiki, R.drawable.fusiki));
words.add(new Word(R.string.firstYearDirection, R.string.xhmeia, R.drawable.xhmeia));
// Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
// adapter knows how to create list items for each item in the list.
WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_first_year);
// Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
// There should be a {@link ListView} with the view ID called list, which is declared in the
// word_list.xml layout file.
ListView listView = (ListView) rootView.findViewById(R.id.list);
// Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
// {@link ListView} will display list items for each {@link Word} in the list.
listView.setAdapter(adapter);
return rootView;
}
}
答案 0 :(得分:1)
我忘了将其声明为清单。
问题解决了。