0

我有一个用户输入的数据列表,需要更新到 sqlite 中。大多数示例仅显示仅使用 OnItemClick 更新数据库,我想要将整个数据列表更新到数据库中。希望有人可以提供帮助。谢谢。

将适配器设置为列表视图

private void setupListViewAdapter() {
    adapter = new NewRowAdapter(this, R.layout.new_row_list_item, new ArrayList<NewRow>());
    ListView NewRowListView = (ListView)findViewById(R.id.NewRowList);
    NewRowListView.setAdapter(adapter);

}

这是在列表视图中添加新行的按钮单击。

private void setupAddRowBtn() {
    findViewById(R.id.AddRow).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            adapter.insert(new AddRow("", 0, 0), 0);                

        }
    });
}

我的适配器:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    NewRowHolder holder = null;

    LayoutInflater inflater = ((Activity) context).getLayoutInflater();
    row = inflater.inflate(layoutResourceId, parent, false);

    holder = new NewRowHolder();
    holder.NewRow = items.get(position);
    holder.name = (TextView)row.findViewById(R.id.Row_name);
    setNameTextChangeListener(holder);
    holder.name.setEnabled(false);
    holder.value = (TextView)row.findViewById(R.id.Row_value);
    holder.value.setRawInputType(Configuration.KEYBOARD_12KEY);
    setValueTextListeners(holder);
    holder.value2 = (TextView)row.findViewById(R.id.Row_value2);
    holder.value2.setRawInputType(Configuration.KEYBOARD_12KEY);
    setValue2TextListeners(holder);

    row.setTag(holder);

    setupItem(holder);
    return row;
}
4

0 回答 0