覆盖或实现超类型方法[错误]

时间:2013-04-28 20:03:13

标签: android listview simplecursoradapter onitemclicklistener onitemclick

我正在尝试创建一个OnItemClick方法来从我的ListView启动另一个活动。创建方法后,我收到多个错误。错误消息是:

  1. LoginList类型的onListItemClick方法(ListView,View,int,long)必须覆盖或实现超类型方法

  2. 对于FragmentActivity类型,未定义onListItemClick(ListView,View,int,long)方法

    我尝试过实施另一种方法(下面),但收到类似的错误。我可以指出我做错了什么。示例帮助最多

  3. 方法:public void onItemClick(AdapterView arg0,View arg1,int arg2,long arg3)

    这是我的班级:

    public class LoginList extends FragmentActivity implements OnClickListener, AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {
    
    private ListView loginList;
    private Button webLogin;
    private SimpleCursorAdapter adapter;
    
    
    
    @Override 
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login_listview);
    
    loginList = (ListView)findViewById(R.id.loginlist);
    loginList.setOnItemClickListener(this);
    
    webLogin = (Button)findViewById(R.id.button3);
    webLogin.setOnClickListener(this);
    
    
    //Specify fileds to display in the list
    String[] from = new String[] { ListProvider.COLUMN_NAME_SITE };
    
    //Bind fields to listview
    int[] to = new int[] {R.id.nameView };
    
    // Create CursorAdapter and set it to display
    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, from, to);
    
    loginList.setAdapter(adapter);
    
    getSupportLoaderManager().initLoader(0, null, this);      
    }
    
    @Override
    public void onListItemClick (ListView l, View v, int position, long id) {  // 1.The method onListItemClick(ListView, View, int, long) of type LoginList must override or implement a supertype method
    
    super.onListItemClick (l, v, position, id); //2. The method onListItemClick(ListView, View, int, long) is undefined for the type FragmentActivity
    
    startActivity(new Intent(this, UpdateDeleteLoginList.class)
        .putExtra(ListProvider.COLUMN_ROWID, id));
    }
    
    @Override
    public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Intent webLoginIntent = new Intent (this, LoginPlusActivity.class);
    startActivity(webLoginIntent);
    }
    
    @Override
    public Loader<Cursor> onCreateLoader(int ignored, final Bundle args) {
    return new CursorLoader(this, ListProvider.CONTENT_URI, null, null, null, null);
    }
    
    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor); 
    }
    
    @Override
    public void onLoaderReset (Loader<Cursor> loader) {
    adapter.swapCursor(null);
    
    }
    
    } 
    

2 个答案:

答案 0 :(得分:1)

扩展FragmentActivity但不使用片段。

您有两个选择:

第一个创建片段扩展ListFragment,这是你实现onClick方法

第二次延伸ListActivity而不是

答案 1 :(得分:0)

我通过选择正确的导入(android.view.View.OnClickListener)解决了这个问题。我导入了“android.content.DialogInterface.OnClickListener”,这给了我一个samme错误。