CheckBox的使用(四):ListView中的项设置为可以多选

在ListActivity中,用getListView获取对象,用ListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE)

package com.example.androidtest;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.app.ListActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.util.Log;

public class MainActivity extends ListActivity {
	

	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_main);
		
		setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, GENRES));;
		
		final ListView listView = getListView();
		listView.setItemsCanFocus(false);
		listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
		
	}	
	
	private static final String[] GENRES = new String[] {"Action",
		"Adventure", "Animation", "Children", "Comedy", "Documentary", "Drama",
		"Foreign", "History", "Independent", "Romance", "Sci-fi", "Television", "Thriller"};

	
}


你可能感兴趣的:(CheckBox的使用(四):ListView中的项设置为可以多选)