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

  • 相关阅读:
    PHP笔记2__变量/字符串/类型转换/常量/,,
    hdu 5108 Alexandra and Prime Numbers(水题 / 数论)
    C#课程设计----------C#学生成绩管理系统
    Java各种学习资源(视频+文档)
    基于慕课网-----Java验证码的实现
    数组prototype添加函数呢,采用回调判定函数内容
    js正则表达式
    jsunit测试
    bind,call,apply区别
    JS技巧
  • 原文地址:https://www.cnblogs.com/hangekgmx/p/6899176.html
Copyright © 2011-2022 走看看