J'ai un simple modèle de ligne et un ListView dans un fragment; le ListView est correctement rempli, avec toutes les dimensions, couleurs, etc. correctes. Le problème est, en cliquant sur une rangée ne déclenche aucun événement.ListView n'est pas cliquable, tous les widgets dans les lignes sont TextView
Le code dans mon fragment est:
MyAdapter mAdapter = new MyAdapter(getActivity().getApplicationContext(), R.layout.list_row, strings);
mList.setAdapter(mAdapter);
mList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d("LIST", "Selected item # " + position);
}
});
La mise en page de fragment (un morceau de celui-ci) est:
<ListView
android:id="@+id/m_list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_margin="20dp"
android:clickable="true"
android:longClickable="true">
</ListView>
La mise en ligne est:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:id="@+id/txt_surname"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1"
android:text="@string/surname"
style="@style/ListStyleXLarge"/>
<!-- 4 more TextView just as the first one -->
</LinearLayout>
Le style est simplement:
<style name="ListStyleXLarge">
<item name="android:textSize">
@dimen/text_size_large
</item>
<item name="android:textStyle">
bold
</item>
<item name="android:textColor">
@color/list_item_text_color
</item>
</style>
Que peut résoudre ce problème? J'ai déjà essayé de définir le
android:clickable="false"
android:focuseable="false"
android:focuseableInTouchMode="false"
à tous les TextViews, mais rien pour l'instant.
Avez-vous essayé d'utiliser ListFragment? http://developer.android.com/reference/android/app/ListFragment.html – FeelGood
Maintenant, ça marche, merci! – frapontillo
S'il vous plaît vérifier ci-dessous le lien plus utile pour vous http://www.vogella.de/articles/AndroidListView/article.html – Nikhil