Как получить идентификаторы нескольких завышенных просмотров? - PullRequest
0 голосов
/ 08 июня 2019

Используя завышенные представления, я получаю кнопки добавления и удаления.И я получаю несколько представлений. И кнопка onclick, получая только последний идентификатор представления. Мне нужно получить все идентификаторы представления в цикле, но я не могу получить идентификаторы нескольких добавленных представлений. Как получить идентификаторы нескольких завышенных представлений.

addBuildingSuper.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                final View addView = inflater.inflate(R.layout.add_edittext, null);
                final FrameLayout frame = addView.findViewById(R.id.frame);
                  btnCustomSuper = addView.findViewById(R.id.btnCustomSuper);
                ImageView remove = addView.findViewById(R.id.remove);

                remove.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((LinearLayout) addView.getParent()).removeView(addView);
                    }
                });
                customSupersLayout = new LinearLayout(getApplicationContext());
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                customSupersLayout.setLayoutParams(layoutParams);
                framer.addView(customSupersLayout);
                customSupersLayout.setVisibility(View.GONE);
                customSupersLayout.setClickable(true);
                View child = getLayoutInflater().inflate(R.layout.supers_dropdown, null);
                customSupersLayout.addView(child);
                LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                child.setLayoutParams(layoutParams2);
                listSupers = child.findViewById(R.id.listSupers);

                LinearLayout supers_dropdown=child.findViewById(R.id.spin_super);
                supers_dropdown.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        customSupersLayout.setVisibility(View.GONE);
                    }
                });
                btnCustomSuper.setOnClickListener(new View.OnClickListener() {
                    @Override

                    public void onClick(View v) {
                        if (customSupersLayout.getVisibility()==View.GONE){
                            btnCustomSuper = (Button) v;


                            try {
                                for (int i=0;i<jsonArray1.length();i++){
                                    JSONObject jsonObject = jsonArray1.getJSONObject(i);
                                    Log.i("supersadd",jsonObject.getString("name"));
                                    msupers.add(jsonObject.getString("name"));
                                    sArrayAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.text_dropdown, msupers);
                                    synchronized (sArrayAdapter){
                                        sArrayAdapter.notifyDataSetChanged();
                                        //sArrayAdapter.notifyAll();
                                        listSupers.invalidate();
                                    }

                                    listSupers.setAdapter(sArrayAdapter);
                                }
                            }catch (Exception e){
                                e.printStackTrace();
                            }



                            customSupersLayout.setVisibility(View.VISIBLE);
                        }else {
                            customSupersLayout.setVisibility(View.GONE);
                        }


                    }
                });

                listSupers.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {



                          listSupers = (ListView)parent;

                        synchronized (sArrayAdapter){
                            sArrayAdapter.notifyDataSetChanged();
                              sArrayAdapter.notifyAll();
                            listSupers.invalidate();
                        }


                        btnCustomSuper.setText(msupers.get(position));
                        listSupers.setTag(position);
                        JSONObject json = null;
                        try {
                            json = jsonArray1.getJSONObject(position);
                            getSuperId=json.getString("id");
                            superId.add(getSuperId);
                            Log.i("msg","btnCustomSupersID"+superId);
                             jsonObject = jsonArray1.getJSONObject(position);

                               Log.i("msg","listID"+listID);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        Log.i("msg","btnCustomSupers"+btnCustomSuper.getText().toString());
                            customSupersLayout.setVisibility(View.GONE);




                    }
                });


                layout.addView(addView);
            }
        });

Это код для завышенных просмотров

1 Ответ

1 голос
/ 08 июня 2019

Попробуйте использовать setTag для вашего View при добавлении rootView

addView.setTag(counter);
rootView.addView(addView);

и получите View, используя тот же тег.

View addView = rootView.findViewWithTag(counter)

Где счетчик можетбыть чем угодно, но отличаться для всех видовмакет, сделайте это:

addView.setTag(counter);
layout.addView(addView);
...