我在将项目插入数据库时遇到问题。我的 ListView 中有 6 个项目并为它创建了数据库。当我单击某个项目插入数据库时,插入了 6 个项目而不是某个项目。我觉得这与我的插入代码有关。
以下是将项目插入数据库表的插入代码。
@Override
public void onListItemClick(ListView l, View v, int position, long id)
{
buddyDB.open();
long _id;
super.onListItemClick(l, v, position, id);
Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
c.moveToPosition(position);
/*TextView contactName = (TextView) findViewById(R.id.contactName);
String NameValue = contactName.getText().toString();
TextView contactNameTwo = (TextView) findViewById(R.id.contactName);
String NameValueTwo = contactName.getText().toString();
TextView contactNameThree = (TextView) findViewById(R.id.contactName);
String NameValueThree = contactName.getText().toString();
TextView contactNameFour = (TextView) findViewById(R.id.contactName);
String NameValueFour = contactName.getText().toString();
TextView contactNameFive= (TextView) findViewById(R.id.contactName);
String NameValueFive = contactName.getText().toString();
TextView contactNameSix = (TextView) findViewById(R.id.contactName);
String NameValueSix = contactName.getText().toString();*/
Toast.makeText(getBaseContext(),
"Selected: " + buddiesList[position], Toast.LENGTH_SHORT).show();
_id = buddyDB.insertContact("Kanak Priya");
_id = buddyDB.insertContact("Joanne Liew");
_id = buddyDB.insertContact("Michelle Lam");
_id = buddyDB.insertContact("Melissa Haiting");
_id = buddyDB.insertContact("Teo Kin Hua");
_id = buddyDB.insertContact("David Yeo");
buddyDB.close();
Intent i = new Intent(context, PersonalInfo.class);
startActivity(i);
}
任何帮助将不胜感激。=)