高级控件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高级控件相关的知识,希望对你有一定的参考价值。

7.ListView事件接口
setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener) 选项选中时触发
setOnItemClickListener(AdapterView.OnItemClickListener listener) 选项单击时触发
setOnItemLongClickListener(AdaoterView.OnItemLongClickListener.listener) 选项长按时触发

lv1.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Map<String,Object> dateMap=(Map<String, Object>) adapter.getItem(position);
String value=(String) dateMap.get("txt");
Log.i("aa", value);
}
});

8.ListActivity的使用
String [] date=getResources().getStringArray(R.array.city);

ArrayAdapter<String> ada=new ArrayAdapter<String>(
this
,android.R.layout.simple_list_item_multiple_choice
, date);
//设置adapter
setListAdapter(ada);
//设置ListVIew的选择行为:复选
ListView lv=getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

9.网格列表GridView
gv=(GridView) findViewById(R.id.gv);
List<Map<String, Object>> date=
new ArrayList<Map<String,Object>>();
//获得所有图片
Field[] fs=R.drawable.class.getDeclaredFields();
for(Field field:fs){
Map<String, Object>maps=new HashMap<String, Object>();
try {
int id=field.getInt(R.drawable.class);
maps.put("png", id);
date.add(maps);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
adapter=new SimpleAdapter(this,
date, R.layout.gridlist_item,
new String[]{"png"},
new int[]{R.id.iv99});
gv.setAdapter(adapter);

gv.setOnItemClickListener(new ItemClickImpl());
}
public class ItemClickImpl implements OnItemClickListener{

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
ImageView iv=new ImageView(GridViewImpl.this);
iv.setScaleType(ScaleType.CENTER);
iv.setLayoutParams(
new LinearLayout.LayoutParams
(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
Map<String, Integer> map=(Map<String, Integer>) adapter.getItem(position);
iv.setImageResource(map.get("png"));
Dialog d=new AlertDialog.Builder(GridViewImpl.this)
.setTitle("显示图片")
.setView(iv)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

}
})
.create();
d.show();
}

以上是关于高级控件的主要内容,如果未能解决你的问题,请参考以下文章

高级控件

RecyclerView高级控件-附实例android专题

高级控件安卓5——ListActivity

Android学习—— Android高级控件

高级控件安卓6—— Gallery

Android高级控件