我是一名非常新的程序员,并且一直在阅读“开始Android 4游戏开发”,以便能够为应用程序商店制作一个简单的游戏。但是,在运行此代码时,当我尝试单击列表中的第一个元素时,onListItemClick不会触发,当我尝试插入覆盖语句时,如下所示,该行上会出现错误。我附上活动第一个列表项应该去,并感谢任何帮助。非常感谢你提前!
package com.example.chapter4androidbasics;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class AndroidBasicsStarter extends ListActivity {
String tests[] = { "LifeCycleTest", "SingleTouchTest", "MultiTouchTest", "KeyTest",
"AccelerometerTest", "AssetsTest",
"ExternalStorageTest", "SoundPoolTest", "MediaPlayerTest", "FullScreenTest",
"RenderViewTest", "ShapeTest", "BitmapTest",
"FontTest", "SurfaceViewTest" };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, tests));
}
@Override
protected void onListItemCLick(ListView list, View view, int position, long id) {
super.onListItemClick(list, view, position, id);
String testName = tests[position];
try {
Class clazz = Class.forName("com.example.chapter4androidbasics." + testName);
Intent intent = new Intent(this, clazz);
startActivity(intent);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
package com.example.chapter4androidbasics;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class LifeCycleTest extends Activity{
StringBuilder builder = new StringBuilder();
TextView textView;
private void log(String text) {
Log.d("LifeCycleTest", text);
builder.append(text);
builder.append("\n");
textView.setText(builder.toString());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = new TextView(this);
textView.setText(builder.toString());
setContentView(textView);
log("created");
}
@Override
protected void onResume() {
super.onResume();
log("resumed");
}
@Override
protected void onPause() {
super.onPause();
log("paused");
if (isFinishing()) {
log("finishing");
}
}
}
答案 0 :(得分:0)
清理并重建您的项目/模块。尝试关闭然后打开它,最后尝试重新启动IDE。这些@Override
注释错误时有发生,无法想象。