如何在customlistview中维护每个EditText的值

时间:2016-04-14 03:51:28

标签: java android listview android-studio

美好的一天,我在自定义列表视图中维护每个EditText的值时遇到问题,例如我旋转屏幕,每个值都消失了, 请帮助我,我应该采取什么方法,提前谢谢。

enter image description here

图片适配器

prototypes

3 个答案:

答案 0 :(得分:4)

PSP 模型中添加 setQuantity getQuantity getter-setter 方法)。

    String pricex = psp.getQuanntity();
                int xx = Integer.parseInt(pricex);
                int total = xx + 1;
                String totalx = Integer.toString(total);
    handler.qty.setText(totalx);

     handler.add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {    
                //add
                psp.setQuantity(yourQuantity++);
                notifyDataSetChanged();
              }
        });

 handler.minus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {    
                //add
                psp.setQuantity(yourQuantity--);
                notifyDataSetChanged();
              }
        });

我希望它对你有所帮助。

答案 1 :(得分:0)

希望这对你有用 - 在清单文件的活动标签中使用它 -

        android:configChanges="orientation|keyboardHidden|screenSize"

如果这不适合你,请告诉我。

答案 2 :(得分:0)

使用此方法存储值

 public void onSaveInstanceState(Bundle savedState) {

        super.onSaveInstanceState(savedState);

        // Note: getValues() is a method in your ArrayAdapter subclass
        String[] values = mAdapter.getValues(); 
        savedState.putStringArray("myKey", values);

    }

然后,您可以在onCreate方法或onCreateViewonActivityCreated中检索数据,如下所示:

public void onCreate (Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        String[] values = savedInstanceState.getStringArray("myKey");
        if (values != null) {
           mAdapter = new MyAdapter(values);
        }
    }

    ...

}