ListView在启动时崩溃

时间:2014-04-12 11:13:50

标签: java android listview

在我学习android视图中的listview的过程中,我创建了一个列表视图,其中的项目在点击时执行某项任务。没有语法错误。但是,应用程序在启动时崩溃了。请帮忙。

package com.mavenmaverick.listviewtest;

import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

 public class ActivityExample extends ListActivity{

 static final String[] CHOICES = new String[]{

             "Open Website",
             "Open Contacts",
             "Open Phone Dialler"
      };

 @Override
 protected void onCreate(Bundle savedInstanceState) {                    
         super.onCreate(savedInstanceState);

      setListAdapter((ListAdapter) new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, CHOICES));   
      getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
      getListView().setTextFilterEnabled(true);
      getListView().setOnItemClickListener(new OnItemClickListener() 
      {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            switch (arg2) {
            case 0:
                startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.developer.android.com")));
                break;

            case 1:
                startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("content://contacts/people/")));
                break;

            case 2:
                startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("tel:22237589")));
                break;

            default:
                break;
            }

        }  

    });
 }
}

LogCat

0 个答案:

没有答案