我有一个用户输入的数据列表,需要更新到sqlite。大多数示例只是通过使用OnItemClick显示更新数据库,我想要的是将整个数据列表更新到数据库中。希望有人能提供帮助。 感谢。
将适配器设置为listview
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;
}