【问题标题】:OnClick on subItem of listview item in androidOnClick on android中listview项目的子项目
【发布时间】:2016-01-07 15:33:13
【问题描述】:

我有一个列表视图。它的项目有子项目。我怎样才能在子项目上获得 onclick 事件。问题是即使在子项目上也能获得 onclick,我必须首先在项目上获得 onclick,然后是子项目。我怎样才能直接点击子项

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
                        final int a = i + 1;
                        final FrameLayout frameLayout = (FrameLayout) view.findViewById(R.id.luxonetopimageid);
                        final FrameLayout frameLayout1 = (FrameLayout) view.findViewById(luxtwotopimageid);

                        frameLayout.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                int m = (a * 2) - 1;
                                if (arrays[m] == 0) {
                                    if (arraysAmount(arrays) < Integer.parseInt(PreferenceUtils.getNumberPassenger(SelectedVagonActivity.this))) {
                                        frameLayout.setBackgroundResource(R.drawable.place_luks_busy);
                                        arrays[m] = m;
                                    } else
                                        Toast.makeText(SelectedVagonActivity.this, "You can not choose more people that you have ex", Toast.LENGTH_LONG).show();

                                } else {
                                    frameLayout.setBackgroundResource(R.drawable.place_luks_free);
                                    arrays[m] = 0;
                                }
                            }
                        });
                        frameLayout1.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                                int n = a * 2;
                                if (arrays[n] == 0) {
                                    if (arraysAmount(arrays) < Integer.parseInt(PreferenceUtils.getNumberPassenger(SelectedVagonActivity.this))) {
                                        frameLayout1.setBackgroundResource(R.drawable.place_luks_busy);
                                        arrays[n] = n;
                                    } else
                                        Toast.makeText(SelectedVagonActivity.this, "You can not choose more people that you have ex", Toast.LENGTH_LONG).show();

                                } else {

                                    frameLayout1.setBackgroundResource(R.drawable.place_luks_free);
                                    arrays[n] = 0;
                                }
                            }

                        });
                    }
                });
            } 

【问题讨论】:

  • 改用ExpandableListView
  • 你能推荐一个更好的方法吗?

标签: android listview subitem


【解决方案1】:

TableView 是最好的选择

【讨论】:

    猜你喜欢
    • 2014-02-13
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多