hie*_*iei 230 android listview
Activity
班级代码:
conversationList = (ListView)findViewById(android.R.id.list);
ConversationArrayAdapter conversationArrayAdapter=new ConversationArrayAdapter(this, R.layout.conversation_list_item_format_left, conversationDetails);
conversationList.setAdapter(conversationArrayAdapter);
conversationList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Log.d("test","clicked");
}
});
Run Code Online (Sandbox Code Playgroud)
类中的getView
函数Adapter
:
if (v == null) {
LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(leftSideMessageNumber.equals(m.getTo())) {
v = vi.inflate(R.layout.conversation_list_item_format_left, null);
} else {
v = vi.inflate(R.layout.conversation_list_item_format_right, null);
}
}
Run Code Online (Sandbox Code Playgroud)
在充气时使用两个xmls有问题吗?
Bha*_*ara 714
我刚从这里找到了解决方案......但是通过深度点击......
如果列表中的任何行项包含可聚焦或可单击的视图,则OnItemClickListener
无效.
行项必须具有类似的参数android:descendantFocusability = "blocksDescendants"
.
在这里,您可以看到示例,列表项应该如何.您的列表项xml应为... row_item.xml(your_xml_file.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Jan*_*pas 57
对于我的列表,我的行还有其他可以点击的东西,比如按钮,所以做一个毯子的块后代不起作用.相反,我在按钮的xml中添加一行:
android:focusable="false"
Run Code Online (Sandbox Code Playgroud)
这样可以防止按钮阻止行上的点击,但仍然可以让按钮获取点击次数.
Edd*_*ddy 30
你需要在listview_item.xml中执行两个步骤
android:descendantFocusability="blocksDescendants"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
这是一个例子:listview_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center_vertical"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<RadioButton
android:id="@+id/script_name_radio_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000"
android:padding="5dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Mil*_*kla 19
在listview的自定义行布局中使用以下代码内部的按钮标记
android:focusable="false"
android:clickable="false"
Run Code Online (Sandbox Code Playgroud)
小智 17
我有同样的问题,我刚看到我不小心设置了:
@Override
public boolean isEnabled(int position)
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
在我的CustomListViewAdapter类上.
通过将其更改为:
return true;
Run Code Online (Sandbox Code Playgroud)
我设法解决了这个问题.以防万一有人犯了同样的错误......
小智 17
使用android:descendantFocusability
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dip"
android:background="@color/light_green"
android:descendantFocusability="blocksDescendants" >
Run Code Online (Sandbox Code Playgroud)
在根布局中添加以上内容
RAJ*_*GAM 11
1.在list_items.xml的Linear Layout中添加以下内容
android:descendantFocusability="blocksDescendants"
2. list_items.xml中的LinearLayout的Child视图
android:focusable="false"
Run Code Online (Sandbox Code Playgroud)
sav*_*ion 10
如果您的文本视图,按钮或stg仅可在行视图中单击或选择
android:descendantFocusability="blocksDescendants"
Run Code Online (Sandbox Code Playgroud)
是不足够的.你必须设置
android:textIsSelectable="false"
Run Code Online (Sandbox Code Playgroud)
到您的textviews和
android:focusable="false"
Run Code Online (Sandbox Code Playgroud)
到你的按钮和其他可聚焦的项目.
Gok*_*rni 10
即使我有同样的问题,我有复选框,做了以下掩蔽itemClickListener工作,
在复选框中添加了以下属性:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
Run Code Online (Sandbox Code Playgroud)
和ItemClickListner开始工作.
有关详细示例,您可以浏览链接,
http://knowledge-cess.com/android-itemclicklistner-with-checkbox-or-radiobutton/
希望它能帮助干杯!
我有同样的问题,并尝试了所有提到的解决方案无济于事.通过测试我发现使文本可选择阻止了调用者的调用.因此,通过将其切换为false或删除它,我的侦听器再次被调用.
android:textIsSelectable="false"
Run Code Online (Sandbox Code Playgroud)
希望这有助于像我一样被困的人.
在主布局中添加这个
android:descendantFocusability="blocksDescendants"
Run Code Online (Sandbox Code Playgroud)将此代码写入每个具有 onClick 的按钮、Textview、ImageView 等
android:focusable="false"
android:clickable="false"
Run Code Online (Sandbox Code Playgroud)希望它会起作用。
归档时间: |
|
查看次数: |
125657 次 |
最近记录: |