我正在使用包含2个不同子项的可扩展ListView.子布局包含3个EditText字段.当我展开组时,它会显示子布局,但我无法在edittext字段中键入任何文本.
我在自定义可扩展列表适配器中的代码如下:
public View getChildView(int groupPosition, int childPosition, boolean arg2, View childView,
ViewGroup parent)
{
switch (groupPosition)
{
case 0:
childView = inflater.inflate(R.layout.edit_personal_layout, null);
final EditText fname = (EditText)childView.findViewById(R.id.editTextFname);
fname.setOnClickListener(new OnClickListener() {
public void onClick(View arg0)
{
// TODO Auto-generated method stub
fname.setFocusable(true);
}
});
break;
case 1:
childView = inflater.inflate(R.layout.edit_experience_layout, null);
break;
case 2:
childView = inflater.inflate(R.layout.edit_qualification_layout, null);
break;
case 3:
childView = inflater.inflate(R.layout.edit_login_layout, null);
break;
case 4:
childView = inflater.inflate(R.layout.edit_other_layout, null);
break;
}
return childView;
}
public View getGroupView(int position, boolean arg1, View view, ViewGroup parent)
{
if(view==null)
{
view = inflater.inflate(R.layout.edit_head, null);
}
TextView head = (TextView)view.findViewById(R.id.list_item_text_view_head);
head.setText(menu[position]);
return view;
}
解决方法:
1)可能是你的editText没有得到焦点,这就是为什么你不能输入任何东西.尝试使用以下行播放到xml-layout文件中.
android:descendantFocusability="blocksDescendants"
有关将焦点放在子元素上的更多信息,请参阅此link.
2)如果上述解决方案无法正常工作,您可以尝试在列表视图中添加.
android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:descendantFocusability="beforeDescendants"
/>
并更改mainfest.xml中的活动:
希望这能解决你的问题.
标签:android,android-edittext,expandablelistview
来源: https://codeday.me/bug/20190620/1245929.html