0

我有一种方法可以将项目添加到Group View

void addItem(String name,String quantity,String value,ViewGroup view_group,int index)
    {
        LayoutInflater layoutInflater = (LayoutInflater)myAct.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        LinearLayout itemLayout = (LinearLayout) layoutInflater.inflate(R.layout.request_object_list, null);

        ((TextView)itemLayout.findViewById(R.id.object_name)).setText(name);

        ((TextView)itemLayout.findViewById(R.id.object_quantity)).setText(quantity);

        ImageButton botaoAdd = ((ImageButton)itemLayout.findViewById(R.id.addButton));
        ImageButton botaoSubtract = ((ImageButton)itemLayout.findViewById(R.id.subtractButton));

        buttons.put(botaoAdd, ((TextView)itemLayout.findViewById(R.id.object_quantity)));
        buttons.put(botaoSubtract, ((TextView)itemLayout.findViewById(R.id.object_quantity)));

        botaoAdd.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                ImageButton botao = (ImageButton)arg0;

                TextView textView = buttons.get(botao);

                Integer quantidade = Integer.parseInt(textView.getText().toString());

                quantidade++;

                textView.setText(quantidade.toString());
            }
        });

        botaoSubtract.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                ImageButton botao = (ImageButton)arg0;

                TextView textView = buttons.get(botao);

                Integer quantidade = Integer.parseInt(textView.getText().toString());

                if(quantidade != 1)
                    quantidade--;

                textView.setText(quantidade.toString());
            }
        });

        ((TextView)itemLayout.findViewById(R.id.object_value)).setText(value);
        (itemLayout.findViewById(R.id.select_check)).setVisibility(View.VISIBLE);
        (itemLayout.findViewById(R.id.select_check)).setId(index);

        view_group.addView(itemLayout);
    }

如您所见,我有 2 个按钮,可以对Group View. 尽管重新加载后Activity,组视图的项目与最初添加时的值完全相同。如何提交更改?

4

0 回答 0