【发布时间】:2011-10-02 17:17:23
【问题描述】:
我有一个简单的行模型和一个片段中的 ListView; ListView 得到正确填充,具有所有正确的尺寸、颜色等。问题是,单击一行不会触发任何事件。
我的片段中的代码是:
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);
}
});
片段布局(一部分)是:
<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>
行布局为:
<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>
风格很简单:
<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>
什么可以解决这个问题?我已经尝试设置
android:clickable="false"
android:focuseable="false"
android:focuseableInTouchMode="false"
到所有的 TextViews,但到目前为止还没有。
【问题讨论】:
-
请查看下面的链接对您更有帮助vogella.de/articles/AndroidListView/article.html
-
我按照迄今为止阅读的每个教程中的所有内容进行了操作,并且应该可以正常工作。事实上,使用 android 的默认简单行填充列表一切正常。这就是为什么我认为问题出在行布局上。
-
请尝试自定义列表视图示例saigeethamn.blogspot.com/2010/04/…
-
你试过使用 ListFragment 吗? developer.android.com/reference/android/app/ListFragment.html
-
试过了。问题似乎出在行布局中,因为我真的无法让它工作。
标签: android list listview textview row