当我添加视图到ListView项目,这个项目不能正常反应 [英] When I add a view to a ListView Item, this Item reacts no longer properly
问题描述
我想,一个新的查看
出现在我的的ListView
项目
,如果我点击这个项目就是这样,其中(1)和(2)点击
和我能做到这一点,但是当我想再次点击该项目
,即隐藏新的查看
,然后项目
点击它应该做的方式也不再响应。
我执行添加
视图操作在我的 onItemClickListener
权的正确位置。
我的code是以下
...
list_view.setOnItemClickListener(新OnItemClickListener(){
@覆盖
公共无效onItemClick(适配器视图<>母公司,观景,INT位置,长的id){
Log.i(TAG,onItemClick :: BEGIN); 开关(位置){
情况下0:
Log.i(TAG,onItemClick :: addTitle之前);
showFieldList(视图);
Log.i(TAG,onItemClick ::后addTitle);
打破;
...
} Log.i(TAG,onItemClick :: END);
}
});
...
我试图表明我的登录
和第一点击后,我可以看到我的登录
进入行为TAG的价值观
onItemClick :: BEGIN
onItemClick :: addTitle之前
onItemClick :: addTitle后
onItemClick :: BEGIN
但接下来点击显示什么和说,那项目
没有反应了,但我可以看到我的,而不是client_adapter LOG
和 getGroupView
方法只是条目将显示当我点击项目
。
我只是想此话一点,就是它也表现这样的,如果我附上ExpandableListView的 OnGroupExpand / OnGroupCollapse / OnGroupClick听众
。
总结:我有一个的ListView
,如果我单击第一个项目,这其中展开并显示一个 ExpandableListView
如果I'click再次,这应该是崩溃,但这并不这样的表现,让 ExpandableListView
假设在整个项目的控制权。
谁能告诉我,为什么项目
失去的点击控制,这是由荣获 ExpandableListView
FieldList中?
谢谢你在前进!
code的休息
私人查看showFieldList(查看视图){ //检索项目布局。 (=查看布局)
RelativeLayout的item_layout =(RelativeLayout的)view.findViewById(R.id.relLayoutDrawer); //检索称号元素
TextView的title_tv =(TextView中)view.findViewById(R.id.title); 查看排= View.inflate(背景下,R.layout.field_list,NULL); //获取字段名
资源解析度= getResources();
字符串字段= res.getString(R.string.fields); 客户端=(ExpandableListView)row.findViewById(R.id.field_expandable_list); client.setFocusable(假); //<<添加到WORK client_adapter =新ClientAdapter(背景下,场); //当我评论这条线,`onItemClick`作品
//如果没有,那么client_adapter assummes控制 client.setAdapter(client_adapter); //称号下设置字幕都对准左边框
params.addRule(RelativeLayout.ALIGN_LEFT,title_tv.getId());
params.addRule(RelativeLayout.BELOW,title_tv.getId());
item_ayout.addView(行,则params);
}
下面我 drawer_list_item.xml
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / relLayoutDrawer
机器人:layout_width =match_parent
机器人:layout_height =48dp
机器人:背景=@机器人:彩色/黑白> < ImageView的
机器人:ID =@ + ID /图标
机器人:layout_width =25dp
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignBottom =@ + ID /标题
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:layout_marginLeft =12dp
机器人:layout_marginRight =12dp
机器人:contentDescription =@字符串/ desc_list_item_icon/> <的TextView
机器人:ID =@ + ID /标题
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =match_parent
机器人:layout_toRightOf =@ ID /图标
安卓了minHeight =机器人:ATTR /列表preferredItemHeightSmall
机器人:textAppearance =机器人:ATTR / textAppearanceListItemSmall
机器人:文字颜色=@彩色/ metallic_silver
机器人:重力=center_vertical
机器人:paddingRight =40dp/> < TextView的机器人:ID =@ + ID /计数器
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:背景=@布局/ counter_bg
机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真
机器人:layout_marginRight =8DP/>< / RelativeLayout的>
解决了!
我正确地又写了一封信 onCollapsedGroupListener
, onExpandedGroupListener
和 onClickedGroupListener
和我添加的下一行到最后code
客户端=(ExpandableListView)row.findViewById(R.id.field_expandable_list);
...
client.setFocusable(假);
I want,a new View
appears in my ListView
Item
, if I click this Item like this, where (1) and (2) are clicks
and I can do it, but when I want to click again this Item
, i.e. to hide that new View
, then Item
click reacts no longer in the way it should do.
I perform the add
View Operation in my onItemClickListener
right to the properly position
My code is the following
...
list_view.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("TAG", "onItemClick:: BEGIN");
switch (position) {
case 0 :
Log.i("TAG", "onItemClick:: before addTitle");
showFieldList(view);
Log.i("TAG", "onItemClick:: after addTitle");
break;
...
}
Log.i("TAG", "onItemClick:: END");
}
});
...
I tried to show the behaviour in my Log
and after the first Click I can see my Log
Entry "TAG" with the values
onItemClick:: BEGIN
onItemClick:: before addTitle
onItemClick:: after addTitle
onItemClick:: BEGIN
but the next clicks show nothing and as said, that Item
doesn't react anymore but I can see instead my client_adapter LOG
and just the entries of getGroupView
Method are shown when I click on Item
.
I just wanted to remark too, that it also behaves like this, if I attach the OnGroupExpand/OnGroupCollapse/OnGroupClick Listeners
of ExpandableListView.
Sum up: I have a ListView
and if I click the first Item, this one expand to show an ExpandableListView
and if I'click again, this should be collapsed but this doesn't behave like this, so that the ExpandableListView
assumes the control over entire Item.
Can anyone tell me, why the item
loses control of clicks and this is won by the ExpandableListView
FieldList?
Thank you in advance!
Rest of code
private View showFieldList(View view) {
// Retrieving Item Layout. (= view Layout)
RelativeLayout item_layout = (RelativeLayout) view.findViewById(R.id.relLayoutDrawer);
// Retrieving "title" Element
TextView title_tv = (TextView)view.findViewById(R.id.title);
View row = View.inflate(context, R.layout.field_list, null);
// Getting Field names
Resources res = getResources();
String fields = res.getString(R.string.fields);
client = (ExpandableListView)row.findViewById(R.id.field_expandable_list);
client.setFocusable(false); //<< ADDED TO WORK
client_adapter = new ClientAdapter(context, fields);
// When I comment this Line, `onItemClick` works
// if not, then client_adapter assummes control
client.setAdapter(client_adapter);
// Setting "Subtitle" under "title" aligning both left borders
params.addRule(RelativeLayout.ALIGN_LEFT, title_tv.getId());
params.addRule(RelativeLayout.BELOW, title_tv.getId());
item_ayout.addView(row, params);
}
Here my drawer_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relLayoutDrawer"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@android:color/black">
<ImageView
android:id="@+id/icon"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/title"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/desc_list_item_icon" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/icon"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/metallic_silver"
android:gravity="center_vertical"
android:paddingRight="40dp"/>
<TextView android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@layout/counter_bg"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"/>
</RelativeLayout>
Solved!
I properly wrote again onCollapsedGroupListener
, onExpandedGroupListener
and onClickedGroupListener
and I added the next line to the last code
client = (ExpandableListView)row.findViewById(R.id.field_expandable_list);
...
client.setFocusable(false);
这篇关于当我添加视图到ListView项目,这个项目不能正常反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!