@override方法不会覆盖或实现超类型的方法

时间:2014-12-13 20:14:15

标签: java android

我的Android编码问题很小。我对此仍然很陌生并遇到一个小问题。无论我似乎做什么,我似乎无法清除我的@override上的错误。错误是@override方法不会覆盖或实现超类型中的方法,并且错误在最后3个@Override的所有3个上。通过它,它出现了菜单,菜单,MenuItem,itmsearch和KeyEvent错误,说找不到符号。任何帮助都会很棒,并提前感谢你。

import android.os.Bundle;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity
{


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    super.setTitle("My Films");

    setContentView(R.layout.main);

    setListAdapter(new ArrayAdapter<String>(this,
    R.layout.film_list_cell,
    R.id.text,
    CELLS));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);
    return true;
}
@Override
public boolean onOptionsItemsSelected(MenuItem item) {
    if (item.getItemId() ==R.id.itmsearch) {
    onSearchRequested();
    return true;
    }
    return false;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if( keyCode == KeyEvent.KEYCODE_SEARCH) {
        onSearchRequested();
        return true;
    }
    return false;
}



static final String[] CELLS = 
        new String[] {"Cell 0", "Cell 1", "Cell 2",
            "Cell 3", "Cell 4", "Cell 5",
            "Cell 6", "Cell 7", "Cell 8", 
            "Cell 9", "CEll 10"};
        }

1 个答案:

答案 0 :(得分:2)

onOptionsItemsSelected更改为onOptionsItemSelected ................................................ ^ < / p>

这里是您要覆盖的方法的正确名称:

  

public boolean onOptionsItemSelected(MenuItem item)

编辑:

  

通过它,菜单,菜单,MenuItem,itmsearch和KeyEvent出现错误,说找不到符号。

确保导入所有相关课程:

import android.view.Menu;
import android.view.KeyEvent;
import android.view.MenuItem;