override or implement a supertype method [ERROR]
我正在尝试创建OniteClick方法以从我的ListView启动另一个活动。创建方法后,我将收到多个错误。错误消息为:
loginlist类型的方法onlistitemclick(listview,view,int,long)必须重写或实现父类型方法
对于类型FragmentActivity,方法OnListItemClick(listView,view,int,long)未定义。
我尝试过实现另一个方法(如下),但收到了类似的错误。我可以让任何人指出我做错了什么。例子帮助最大
方法:public void oniteclick(adapterview arg0,view arg1,int arg2,long arg3)
这是我的课:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 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); } } |
您扩展了fragmentactivity,但不使用片段。
您有两种选择:
首先创建片段扩展列表片段,这是您实现onclick方法
第二个扩展ListActivity
我通过选择正确的导入(android.view.view.onclickListener)解决了这个问题。我导入了"android.content.dialogInterface.onclickListener",这给了我一个samme错误。