我在將項目插入數據庫時遇到了問題。我在我的ListView中有6個項目併爲它創建了數據庫。當我單擊某個項目以插入數據庫時,將插入6個項目而不是某個項目。我覺得這與我的插入代碼有關。將每個項目從ListView插入到sqlite數據庫中的問題
下面是插入代碼插入到數據庫的表中的代碼。
@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);
}
任何幫助將不勝感激。 =)
我試過了,它的工作原理!好極了!謝謝=) – Preeyah 2012-08-01 09:02:51