我想從listview中獲取項目。但是當我嘗試點擊listview我得到錯誤。 可以幫助我一些身體?如何在ListView中使用onItemClickListener獲取項目
這是我的課堂活動。
data = new dbHelper(this);
listKeluar = (ListView)findViewById(R.id.listKeluar);
String [] keluar = { data.k_nama, data.m_chiperteks, data.kel_waktu };
int[] k = { R.id.tNama, R.id.tChiper, R.id.tWaktu };
cursor = data.DataPesanKeluar();
SimpleCursorAdapter keluarAdapter = new SimpleCursorAdapter(this, R.layout.baris_keluar, cursor, keluar, k); //this line my error
listKeluar.setAdapter(keluarAdapter);
listKeluar.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
if(cursor.moveToPosition(arg2)) {
idkeluar = cursor.getString(cursor.getColumnIndex(data.kel_id));//my line error, if i delete this line my listview didn't respon when i click
nama = cursor.getString(cursor.getColumnIndex(data.k_nama));
chiperteks = cursor.getString(cursor.getColumnIndex(data.m_chiperteks));
waktu = cursor.getString(cursor.getColumnIndex(data.kel_waktu));
}
Intent isiPesanKeluar = new Intent();
isiPesanKeluar.setClass(KotakKeluar.this, IsiPesanKeluar.class);
isiPesanKeluar.putExtra("idkeluar", idkeluar);
isiPesanKeluar.putExtra("nama", nama);
isiPesanKeluar.putExtra("chiperteks", chiperteks);
isiPesanKeluar.putExtra("waktu", waktu);
這是我的日誌貓
Java.lang.IllegalStateException: get field slot from row 0 col -1 failed
我的方法
public Cursor DataPesanKeluar() {
Cursor c = dba.rawQuery(
" SELECT "
+ kel_id + " AS _id,"
+ e_chiperteks + ","
+ k_nama + ","
+ kel_waktu +
" FROM " + tbPesan + " INNER JOIN " + tbPesanKeluar +
" ON " + tbPesan + "." + p_idpesan + "=" + tbPesanKeluar + "." + kel_idpesan +
" INNER JOIN " + tbEnkrip +
" ON " + tbPesan + "." + p_idenkrip + "=" + tbEnkrip + "." + e_idenkrip +
" INNER JOIN " + tbKontak +
" ON " + tbPesan + "." + p_idkontak + "=" + tbKontak + "." + k_id , null);
return c;
}
我baris_keluar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tNama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tChiper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/tWaktu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
感謝幫助我.. 問候..
我有嘗試我們的代碼,但我得到了同樣的錯誤,可以ü請幫助我:(我真的需要的解決方案.. – androidDev 2013-05-06 07:56:48
你改變你所有的listCursor to cursor? – 2013-05-06 07:58:28
是的,我已經改變了像ur代碼,但它仍然是相同的錯誤 – androidDev 2013-05-06 08:06:35