簡體   English   中英

Android中ListView項目的子項目的OnClick

[英]OnClick on subItem of listview item in android

我有一個列表視圖。 它的項目有子項目。 我如何在子項上獲取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;
                                }
                            }

                        });
                    }
                });
            } 

TableView是可用的最佳選擇

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM