Android OnItemCLickLIstener不';不能在ListView上工作
我有一个带有ListView的活动。具有自定义视图的ListView。我向ListView添加了一个监听器。当我点击这个项目时,结果什么也看不到。 具有ListView的活动:Android OnItemCLickLIstener不';不能在ListView上工作,android,android-layout,listview,Android,Android Layout,Listview,我有一个带有ListView的活动。具有自定义视图的ListView。我向ListView添加了一个监听器。当我点击这个项目时,结果什么也看不到。 具有ListView的活动: <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@color/silver_conv">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="40dp" android:layout_alignParentTop="true" android:id="@+id/topcontainer"
android:background="@color/black">
</FrameLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/chat_list" android:layout_below="@+id/topcontainer"
android:layout_above="@+id/last_action"
android:cacheColorHint="#00000000"
android:layout_marginRight="2dp" android:clickable="true"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="last action was at time" android:id="@+id/last_action"
android:longClickable="false"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="false" android:layout_above="@+id/action_container"
android:layout_marginBottom="5dp" android:layout_alignParentLeft="false" android:layout_marginLeft="5dp"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="43dp" android:layout_alignParentBottom="true" android:id="@+id/action_container"
android:background="@drawable/conv_botom_action_gradient">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/send"
android:id="@+id/send_message_btn" android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@drawable/blue_button_selector" android:textColor="@color/white"
android:layout_marginLeft="3dp" android:layout_marginTop="3dp"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/add_attach_btn"
android:layout_alignParentLeft="true" android:layout_alignParentBottom="true"
android:background="@drawable/add_attach_button_selector"
android:layout_marginRight="2dp" android:layout_marginBottom="3dp" android:layout_marginTop="3dp"/>
<EditText android:layout_width="40dp" android:layout_height="wrap_content" android:id="@+id/message_et"
android:layout_toRightOf="@+id/add_attach_btn" android:layout_toLeftOf="@+id/send_message_btn"
android:singleLine="true" android:layout_alignParentBottom="true" android:hint="Type message here"
android:background="@drawable/message_input" android:layout_marginBottom="3dp"
android:gravity="center_vertical" android:layout_marginTop="3dp"/>
</RelativeLayout>
mConvListView = (ListView)findViewById(R.id.chat_list);
mConvListView.setDivider(null);
mConvListView.setDividerHeight(0);
mConvListView.setItemsCanFocus(false);
mConvListView.setOnItemClickListener(clickLister);
mConvListView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
mConvListView.setStackFromBottom(true);
顺便说一句,很抱歉有很多代码。但是第二天我找不到任何建议。我想你没有按正确的方式得到这个项目。试试这个:
int position = (int) adapterView.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
编辑
试试这段代码
ListView lv = (ListView)findViewById(R.id.chat_list);
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
int position = (int) parent.getSelectedItemId();
Log.i("Position:", Integer.toString(position));
}
});
ListView lv=(ListView)findViewById(R.id.chat_列表);
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父视图、视图v、整型位置、长id){
int position=(int)parent.getSelectedItemId();
Log.i(“位置:”,Integer.toString(位置));
}
});
通过在行布局中设置可聚焦对象,可以阻止ListView获取触摸事件
此FrameLayout正在使用触摸事件:
<FrameLayout
android:id="@+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:focusable="false"/>
删除可聚焦设置,使其看起来像这样:
<FrameLayout
android:id="@+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
(您确实应该组织XML,以便在Eclipse中使用Ctrl+Shift+F时可读。)对所有组件进行聚焦,如下所示:
android:focusable="false"
android:focusableInTouchMode="false"
为什么
AdapterView.onItemClickListener
不是ListView…
。您是否刚刚尝试了mConvListView.setOnItemClickListener(新的OnItemClickListener(){…
<FrameLayout
android:id="@+id/attach_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:focusable="false"
android:focusableInTouchMode="false"