zoukankan      html  css  js  c++  java
  • 控件

    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();
    }

  • 相关阅读:
    malloc函数具体解释
    信息熵(Entropy)究竟是用来衡量什么的?
    机器学习笔记——皮尔逊相关系数
    GridView导出Excel的超好样例
    Microsoft Visual C++ Runtime Library Runtime Error的解决的方法
    编译过程
    java实现第三届蓝桥杯星期几
    java实现第三届蓝桥杯星期几
    java实现第三届蓝桥杯星期几
    java实现第三届蓝桥杯星期几
  • 原文地址:https://www.cnblogs.com/hangekgmx/p/6899176.html
Copyright © 2011-2022 走看看