0

我是 android 新手,我有一个错误创建列表....... 什么是错误?有人帮帮我…………我正在使用api18…………

包 com.example.personalinformationmanagement;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {
    String list[] = {"PersonalTask", "PersonaFileInformation","WeaklyReports", "Remainder"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1));
    }

    /* (non-Javadoc)
     * @see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)
     */
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        String choice = list[position];
        try{
        Class ourClass = Class.forName("com.example.personalinformationmanagement." +choice);
        Intent i = new Intent(MainActivity.this,ourClass);
        startActivity(i);
        }catch(ClassNotFoundException e){
            e.printStackTrace();            
        }

    }


}
4

1 回答 1

0

首先确保您的activity_main.xml 中的listview id 等于“android:id="@android:id/list"。在代码更改行中

setListAdapter(new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,list));

如果您想使用 listView 进行操作,请使用:

ListView myListView = getListview();
于 2013-11-14T10:23:58.507 回答