هذا السؤال لديه بالفعل إجابة هنا:
لدي جزء به قائمة من الدروس:
أريد عند النقر فوق الخيار الأول لفتح طريقة عرض جديدة. كيف يمكنني فعل ذلك؟
يوجد أدناه رمز من الجزء الموجود في الصورة
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;
}
}