您好我的android應用程序中的onItemClick有問題。我嘗試,但我得到一個錯誤。我希望我能從我的列表視圖中獲取來自sqlite數據庫的數據,並且可以單擊此列表中的一個值來啓動具有此值的其他actitiy。看到我的代碼以獲取更多信息:如何在android應用程序中使用onItemClick?
我actitiy:
public class ShowActivity extends ListActivity {
我的方法:
private void ladeDaten() {
Cursor KlassenCursor = mDatenbank.rawQuery(KLASSEN_SELECT_ROW, null);
startManagingCursor(KlassenCursor);
android.widget.SimpleCursorAdapter KlassenAdapter = new android.widget.SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
KlassenCursor,
new String[] {"name"},
new int[] {
android.R.id.text1
});
setListAdapter(KlassenAdapter);
ListView lv = (ListView)findViewById(android.R.id.list);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Cursor cursor = (Cursor)parent.getItemAtPosition(position);
String item = cursor.getString(cursor.getColumnIndex("name"));
Intent intent = new Intent(this,ShowActivity.class); //here is the error
intent.putExtra("iteid", item);
startActivity(intent);
}
});
}
我的佈局: ...
</ListView>
...
我的錯誤:
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<ShowActivity>) is undefined
我該怎麼辦? :(
UPDATE:
public void onItemClick(AdapterView<?> parent,View view,int position,long id){
Cursor cursor = (Cursor)parent.getItemAtPosition(position);
String item = cursor.getString(cursor.getColumnIndex("name"));
Intent intent = new Intent(ShowDayActitiy,ShowDayActivity.class); //here is the error
intent.putExtra("iteid", item);
startActivity(intent);
}
});
我想你開始療法actitiy :(
爲什麼哦爲什麼告訴我們你得到一個錯誤,然後不告訴我們錯誤是什麼?你認爲這些錯誤是隨機的還是不重要的? – Simon
用新的Intent(ShowActitiy.this,ShowDayActivity.class)替換'new Intent(this,ShowActivity.class);'' – njzk2
@ njzk2:這可能是答案。已經有7個答案,但是你全部擊敗了他們,因爲歐普試圖打開** ShowDayActivity **,但沒有提到它呢。 –