我编写了一个 Android 应用程序并使用了 ListView,它工作正常,但是如果我想单击一个项目,那么我想用所选项目启动第二个 Activity。为此,我想使用 OnItemClick 但它不起作用:(
MainActivity.java
package de.linde.listview;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity<T> extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List valueList = new ArrayList<String>();
for(int i=0;i<10;i++)
{
valueList.add("value" + i);
}
ListAdapter adapter = new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,valueList);
final ListView lv = (ListView)findViewById(R.id.listview1);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() { //<-- Error1
@Override
public void OnItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3){ //<-- Error 2
Intent intent = new Intent();
intent.setClassName(getPackageName(), getPackageName() + ".Show_Activity");
intent.putExtra("selected",lv.getAdapter().getItem(arg2).toString());
startActivity(intent);
}
});
}
}
这是我的 Show_Activity.java
package de.linde.listview;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
public class Show_Activity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anzeige);
Intent intent = getIntent();
((TextView)(findViewById(R.id.textView1))).setText("Es wurde" + intent.getStringExtra("selected") + " gewählt!");
}
}
我得到错误 1:
new AdapterView.OnItemClickListener(){} 类型必须实现继承的抽象方法 AdapterView.OnItemClickListener.onItemClick(AdapterView, View, int, long)
我收到错误 2:
类型为 new AdapterView.OnItemClickListener(){} 的方法 OnItemClick(AdapterView, View, int, long) 必须覆盖超类方法
我做错了什么?