-1

以下类是从数据库填充的列表视图的处理程序。它工作正常,但现在我不会在单击项目时开始新活动。我已经从“活动”扩展到“列表活动”,我相信我需要实现一个“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
        }
4

1 回答 1

5

看起来您的onListItemClick()声明在您的onCreate()方法中。把它移到外面onCreate()

于 2013-01-11T15:58:30.973 回答