以下类是从DB填充的listview的处理程序。它工作正常,但现在我点击项目时不会开始新的活动。我已经从'activity'扩展到'listactivity',我相信我需要实现'OnListItemClick()'方法。我在我的班级输入了这个,但是我得到了一个错误,没有导入选项。该错误以'void是变量onListItemClick'
的无效类型给出任何人都可以把我推向正确的方向。
代码:
package com.example.sqliteexample;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.widget.ListView;
public class SQLView extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HotOrNot H = new HotOrNot(this, null, null);
setContentView(R.layout.layout);
ListView listContent = (ListView)findViewById(R.id.contentList);
HotOrNot Content = new HotOrNot(this, null, null);
Content.open();
Cursor cursor = Content.getData();
startManagingCursor(cursor);
@SuppressWarnings("static-access")
String [] from = new String [] {H.KEY_NAME, H.KEY_HOTNESS};
int [] to = new int [] {R.id.txtName, R.id.txtAge};
@SuppressWarnings("deprecation")
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.entries, cursor, from, to);
listContent.setAdapter(cursorAdapter);
public void onListItemClick(ListView l, View v, int position, long id) {
// Do something when a list item is clicked
}
答案 0 :(得分:5)
您的onListItemClick()
声明似乎在onCreate()
方法内。将其移至onCreate()
之外。