检查以下代码:
package com.example.mapsdemo;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.util.SparseBooleanArray;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
public class MainActivity extends Activity {
ArrayList<String> a = new ArrayList<String>();
private ListView lView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fillarray();
lView = (ListView) findViewById(R.id.listView1);
lView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, a));
lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
lView.setOnItemClickListener(new OnItemClickListener() {
private String my_sel_items;
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
// List list = new ArrayList();
my_sel_items = new String("Selected Items");
SparseBooleanArray a = lView.getCheckedItemPositions();
for (int i = 0; i < a.size(); i++) {
if (a.valueAt(i)) {
my_sel_items = my_sel_items + ","
+ (String) lView.getAdapter().getItem(i);
}
}
Log.v("values", my_sel_items);
}
});
}
private void fillarray() {
// TODO Auto-generated method stub
a.clear();
a.add("a");
a.add("b");
a.add("c");
a.add("d");
a.add("e");
}
}
你在日志中的结果
03-26 12:25:06.106: V/values(3301): Selected Items,a
03-26 12:25:06.810: V/values(3301): Selected Items,a,b
03-26 12:25:07.466: V/values(3301): Selected Items,a,b,c
03-26 12:25:08.136: V/values(3301): Selected Items,a,b,c,d
编辑:
检查此链接,您可以在此代码中使用任何字体颜色和列表视图背景颜色。