在我使用我的按钮访问我的列表视图后,在关注代码并显示没有错误后,强制关闭我的代码如下
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Listview extends ListActivity {
String classNames[] = {"home1", "Sweet", "tutorial2"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, classNames));
}@Override
protected void onListItemClick (ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
String openClass = classNames[position];
try{
Class selected = Class.forName("us.beats.with." + openClass);
Intent selectedIntent = new Intent(this, selected);
startActivity(selectedIntent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
答案 0 :(得分:0)
按钮设置的地方我有Button Listview =(Button)findViewById(R.id.Listview); Listview.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("us.beats.with.Mylist"));
mpButtonClick.start();
但是启动活动是us.beats.with.Listview应该是上面的
答案 1 :(得分:-1)
更改您的类名并运行它将正常工作
答案 2 :(得分:-1)
public class MyList extends ListActivity {
String classNames[] = {"home1", "Sweet", "tutorial2"};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, classNames));
}@Override
protected void onListItemClick (ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
String openClass = classNames[position];
try{
Class selected = Class.forName("us.beats.with." + openClass);
Intent selectedIntent = new Intent(this, selected);
startActivity(selectedIntent);
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
现在运行上面的代码