- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个可扩展的 ListView ,当我点击一行时,它会触发 onChildClick 或 onGroupClick,具体取决于我点击的是子项还是组。
如果我在 xml 布局文件中添加可点击的内容(例如复选框),onChildClick 将不再触发。 (如果我添加一个简单的 textView 它也可以工作)
谁知道为什么?该项目是否覆盖了监听器?
主要代码:
View firstView = inflater.inflate(R.layout.main_layout, container, false);
listView = (ExpandableListView) firstView.findViewById(R.id.expandableListView1);
listView.setOnChildClickListener(new OnChildClickListener()
{
@Override
public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, int arg3, long arg4)
{
Toast.makeText(getActivity().getBaseContext(), "Child clicked", Toast.LENGTH_LONG).show();
return false;
}
});
适配器代码:
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context context;
private ArrayList<String> groups;
private ArrayList<ArrayList<FarmaciListItem>> children;
public ExpandableListAdapter(Context context, ArrayList<String> groups,
ArrayList<ArrayList<FarmaciListItem>> children) {
this.context = context;
this.groups = groups;
this.children = children;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return children.get(groupPosition).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
// Return a child view. You can load your custom layout here.
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
FarmaciListItem farmacoItem = (FarmaciListItem) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.child_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvChild);
tv.setText(" " + farmacoItem.getName());
// Depending upon the child type, set the imageTextView01
tv.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
if (farmacoItem instanceof PesoItem) {
tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.car, 0, 0, 0);
}
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return children.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return groups.get(groupPosition);
}
@Override
public int getGroupCount() {
return groups.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
// Return a group view. You can load your custom layout here.
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
String group = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.group_layout, null);
}
TextView tv = (TextView) convertView.findViewById(R.id.tvGroup);
tv.setText(group);
return convertView;
}
最佳答案
问题是因为您的 child 身上有可聚焦的元素。例如考虑一个按钮,默认情况下它将处于聚焦状态。所以将它设置为 false 就可以了。
在你的情况下,也许为复选框添加以下属性
android:focusable="false"
这应该可以解决问题。
关于android - OnChildClickListener 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10686971/
我有一个可扩展的 ListView ,当我点击一行时,它会触发 onChildClick 或 onGroupClick,具体取决于我点击的是子项还是组。 如果我在 xml 布局文件中添加可点击的内容(
我是安卓新手。 我在使用 ExpandableListViewAdapter 时遇到了问题。 当我点击编辑文本框时,onChildClickListener 不工作。 我的问题是它是否适用于编辑文本框
我有一个 ExpandableListView,一切正常。我在每个子行中都有一个复选框,当我点击一个子行时,我想切换它,如下所示: expandableListView.setOnChildClick
适配器 public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context mCo
我的 Android 应用程序上的可扩展 ListView 有问题 这是我的代码 package proyek.akhir; import android.app.ListActivity; impo
我在 ExpandableListView 中有一个包含 2 个 child 的组,我想为点击的 child 的名字设置组名。 如何访问在 getGroupView() 方法中生成的 TextView
我有一个如下所示的 BaseExpandableListAdapter: public View getChildView(final int groupPosition, final int chi
我不知道这段代码有什么问题,我的 onChildClickListener() 没有被调用 我看到一些答案,他们说覆盖 isChildSelected 并返回 true;我也试过了,但仍然没有被调用。
为什么没有打印日志?所有其他人的日志都在工作,但 child 不工作。 确实出现了 TextView 的日志,但是当我使用编辑文本时,它不起作用。 为什么会这样?我哪里错了? ExpandableLi
通过单击一个按钮,我会出现一个对话框,其布局中有一个 ExpandableListView,并填充了复选框: button.setOnClickListener(new View.OnClickLis
我有一个 listView 和 sublistView 项目,我提到了 Using lists in Android (15.2. ExpandableListView 示例)。 我可以通过 Toas
我在使可扩展 ListView 的点击监听器正常工作时遇到问题。我是否正确实现了这一点? 代码: elv = getExpandableListView(); // Set up the adapte
我有关于 onChildClickListener 的代码,如下面的代码 fragment OnChildClickListener occl = new OnChildClickListener()
我有一个动态生成的可扩展 ListView ,子列表包含另一组值,我需要在子列表上设置一个 onChildClickListener,以便通过数据中保存的特定 URL 传递 Web Intent 每个
我是一名优秀的程序员,十分优秀!