如何在Android Studio中点击listview中的项目打开新活动?或者更确切地说 - 我只是一个问题。问题在代码中描述。对不起我的英语不好!!!这是代码`
public class MainActivity extends Activity {
ListView listView;
ArrayAdapter<String> adapter;
String[] android_versions= { "Jelly Bean", "Kitkat", "Donut",
"Eclair", "Froyo", "Honeycomb", "Ice Cream"
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.list_view);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android_versions);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Here´s the problem! The super.OnItemClick
//doesn´t work.//
super.OnItemClick(parent, view, position, id);
//Here´s the problem! The super. doesn´t work.//
if (position == 0) {
Intent intent = new Intent(this, JellyBean.class);
startActivity(intent);
}
else if (position == 1) {
Intent intent = new Intent(this, Kitkat.class);
startActivity(intent);
}
else if (position == 2) {
Intent intent = new Intent(this, Donut.class);
startActivity(intent);
}
}
}
}
}
`
答案 0 :(得分:1)
删除 super.OnItemClick(父级,视图,位置,ID);
Intent myIntent = new Intent(view.getContext(), JellyBean.class);
startActivity(intent);
答案 1 :(得分:0)
由于ItemClickListener
是界面,因此没有super
实施,因此您可以删除super.OnItemClick