我正在从数据库中检索项目名称,项目描述和项目价格,当用户单击项目时,它将进入编辑活动,用户可以更新或删除数据,但是当我单击列表项目时,它会将我带回主活动
当用户单击视图数据时,单击列表视图后,它将显示列表视图,用户应移动到编辑数据活动,其中编辑数据活动将显示在编辑文本框中以进行更新或删除
我的代码在一个参数项目名称下运行良好,但是当我使用项目描述和项目价格时,会出现此错误
private static final String TAG = "ListDataActivity";
DatabaseHelper mDatabaseHelper;
private ListView mListView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_data);
mListView = (ListView) findViewById(R.id.listView);
mDatabaseHelper = new DatabaseHelper(this);
populateListView();
}
private void populateListView() {
Log.d(TAG, "populateListView: Displaying data in the ListView.");
Cursor data = mDatabaseHelper.getData();
ArrayList<String> listData = new ArrayList<>();
while(data.moveToNext()){
listData.add(data.getString(1));
}
ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, listData);
mListView.setAdapter(adapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
String name = adapterView.getItemAtPosition(i).toString();
String des = adapterView.getItemAtPosition(i).toString();
String pri = adapterView.getItemAtPosition(i).toString();
Log.d(TAG, "onItemClick: You Clicked on " + name);
Cursor data = mDatabaseHelper.getItemID(name, des, pri); //get the id associated with that name
int itemID = -1;
while(data.moveToNext()){
itemID = data.getInt(0);
}
}
});
}
慕勒3428872
相关分类