如标题中所述,我没有获得ListView的OnItemClick事件
我的代码:
ListView listView1 = (ListView) findViewById(R.id.listView1);
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast.makeText(SelectQuizActivity.this, "OnItemClick", Toast.LENGTH_LONG).show();
}
});
SimpleAdapter adapter = new SimpleAdapter(this, listView, R.layout.list_layout, new String[]{"topic","by","score"}, new int[]{R.id.textViewTopic,R.id.textViewTopicCreator,R.id.textViewScore});
listView1.setAdapter(adapter);
布局XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".SelectQuizActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/bg_dark_gradient_rev"
android:gravity="center_horizontal"
android:padding="20dp"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textStyle="bold"
android:typeface="sans" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:choiceMode="singleChoice"
android:clickable="true"
android:divider="@drawable/bg_light_gradient"
android:dividerHeight="1dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:listSelector="@drawable/list" >
</ListView>
</RelativeLayout>
答案 0 :(得分:2)
尝试在单行布局文件的每个子项中添加focusable="false"
。它对我有用.. :))
更新: 将android:descendantFocusability添加到父视图也可以。
答案 1 :(得分:0)
试试这个:
listView1.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
Log.i("CLICK", "CLICK CLICK");
}
});