ListView 滚动刷新数据时的 BaseAdapter

BaseAdapter On Scroll Refresh Data in ListView

我是 Java 和 android 的新手...我尝试使用 BaseAdapter 创建 ListView 已成功创建列表 我有一个 EditText 以及每个列表项的按钮但真正的问题是当我将一些数据放入 editText 字段并向下滚动以更改最后一个列表项的值然后我回到顶部它将数据刷新为默认值它不包含用户之前输入的值向下滚动

我的 BaseAdaper 代码

    class CoustomAdptr extends BaseAdapter{

    String[] dates;
    Integer[] inventory;
    Integer totalrooms;
    public CoustomAdptr(RoomFragment roomFragment, String[] dates, Integer[] inventory, Integer totalrooms) {
        this.dates = dates;
        this.inventory = inventory;
        this.totalrooms = totalrooms;
    }

    @Override
    public int getCount() {
        return dates.length;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {

        view = getLayoutInflater().inflate(R.layout.inventory_listview,null);
        TextView textView = (TextView) view.findViewById(R.id.roomListViewText);
        final EditText editText = (EditText) view.findViewById(R.id.roomListInventory);
        final Button updateButton = (Button) view.findViewById(R.id.roomListViewInventoryUpdateButton);
        if(inventory[i] == 0){
            editText.setBackgroundColor(getResources().getColor(R.color.SoldOut));
            editText.setTextColor(getResources().getColor(R.color.SoldOutTextColor));
        } else if(inventory[i] < totalrooms){
            editText.setBackgroundColor(getResources().getColor(R.color.invetory));
            editText.setTextColor(getResources().getColor(R.color.invetoryTextColor));
        } else if(inventory[i] == totalrooms){
            editText.setBackgroundColor(getResources().getColor(R.color.fullInventory));
            editText.setTextColor(getResources().getColor(R.color.fullInventoryTextColor));
        }

        editText.setText(String.valueOf(inventory[i]));
        textView.setText(dates[i]);
        updateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //String name = editText.getText().toString();
                //String name1 = dates[i];
                //String name2 = getArguments().getString("room_id");
                updateButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_done_black_24dp,0,0,0);
                //updateButton.setBackgroundColor(getResources().getColor(R.color.SoldOut));
                updateButton.setText("Updated");
                updateButton.setEnabled(false);
                Toast.makeText(getContext(), "Update Inventory Button Clicked", Toast.LENGTH_LONG).show();
            }
        });
        return view;
    }
}

这就是我向我的适配器传递数据的方式

JSONObject jObj = parentObject.getJSONObject("success");
JSONObject jObj2 = jObj.getJSONObject("data");
JSONArray arrajson = jObj2.getJSONArray("inventories");
String arrayCount = Integer.toString(arrajson.length());
String[] dates = new String[arrajson.length()];
Integer[] inventory = new Integer[arrajson.length()];
Integer totalrooms = new Integer(jObj2.getInt("total_room"));
for (int i=0; i<arrajson.length();i++){
     JSONObject jsonObject = arrajson.getJSONObject(i);
     dates[i] = jsonObject.getString("date");
     inventory[i] = jsonObject.getInt("inventory");
}
CoustomAdptr coustomAdptr = new CoustomAdptr(RoomFragment.this,dates,inventory,totalrooms);
listView.setAdapter(coustomAdptr);

需要帮助 :- 我想在用户向上或向下滚动时保留编辑文本的可见性和价值...我希望我能够清楚地解释我的问题

点击按钮后,将其状态保存在布尔数组或其他地方。在 getView 方法中,检查之前是否单击过此按钮,然后相应地设置视图。

如果您为行创建一个模型 class 会更好。