listActivity总结
1、写一个类继承ListActivity
2、重写onCreate方法,不需要设置内容视图,也即不需要使用setContextView方法
3、使用setListAdapter设置内容
4、重寫onListItemClick為listview監聽點擊事件
实例:
public class ListActivity_Demo extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String []str=new String[20];
for (int i = 0; i <str.length; i++) {
DecimalFormat decimalFormat=new DecimalFormat("##.#");
str[i]=decimalFormat.format(i);
}
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,Arrays.asList(str)));
ImageView imageView=new ImageView(this);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
System.out.println(l+",,,,,"+v+",,,,,,"+position+",,,"+id);
Toast.makeText(this, "safsdf"+position,1).show();
}
}