【问题标题】:How to get Position on Child item in expandablelistview in Android如何在 Android 的可扩展列表视图中获取子项的位置
【发布时间】:2016-08-30 08:24:32
【问题描述】:

我是第一次使用可扩展列表视图适配器。我有一个问题,我没有得到一个线索,如何做到这一点。这是我的孩子 item

的视图

现在我想做的是当我点击 Pending 或 Assign Button 时?它得到上面显示的文本的 id 为了成功。列表中有很多项目,我不能使用 onchildClick 侦听器,因为我需要关注这些按钮,而上面的文本仅从 web 服务加载。我尝试使用 getChildView 或 getChildId 但它给了我最后一个孩子的 id 并且在等待点击时它不会更新孩子 ID。请帮助我做到这一点。我也在适配器中使用 onClick 监听器。

【问题讨论】:

  • 我不想使用 Child positionlistener。因为它不适用于按钮
  • 您是否尝试使用所需数据为适配器中的视图设置标签?像项目ID,孩子ID或任何你想要的?还有你如何处理每个孩子的点击可能与我们分享适配器

标签: android expandablelistview expandablelistadapter


【解决方案1】:

你可以在适配器类中实现点击事件 见下面的例子 我在这里使用 ListAdapter extends BaseExpandableListAdapter{

及其在 ListAdapter 中被覆盖的方法,请查看示例

@Override
public View getChildView(final int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {

    final HashMap mapBinidGrp = allItms.get(groupPosition);
    final ArrayList<ArrayList<String>> itmArys = (ArrayList<ArrayList<String>>) mapBinidGrp.get(mKEY_BIN_ITEMS);
    final ArrayList<String> childText = itmArys.get(childPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_row_layout, null);
    }
    TextView txtListChild6 = (TextView) convertView.findViewById(R.id.tv_one);

    txtListChild6.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // todo
        }
    });

    return convertView;
}

【讨论】:

    猜你喜欢
    • 2016-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-29
    • 2021-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多