即使在“活动重新加载”后,也可以更改“组视图”

时间:2013-04-02 17:34:03

标签: java android

我有一种方法可以将项目添加到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后,组视图的项目与最初添加时的值完全相同。我该如何提交更改?

0 个答案:

没有答案