实现效果图:



布局文件:

vlist2.xml
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageViewandroid:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5px"/> <LinearLayoutandroid:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextViewandroid:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFFFF" android:textSize="22px"/> <TextViewandroid:id="@+id/info" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFFFFFFF" android:textSize="13px"/> </LinearLayout> <Buttonandroid:id="@+id/view_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/s_view_btn" android:layout_gravity="bottom|right"/> </LinearLayout>

程序代码:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 /** * @author allin * */ publicclassMyListView4 extendsListActivity { privateList<Map<String, Object>> mData; @Override publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mData = getData(); MyAdapter adapter = newMyAdapter(this); setListAdapter(adapter); } privateList<Map<String, Object>> getData() { List<Map<String, Object>> list = newArrayList<Map<String, Object>>(); Map<String, Object> map = newHashMap<String, Object>(); map.put("title", "G1"); map.put("info", "google 1"); map.put("img", R.drawable.i1); list.add(map); map = newHashMap<String, Object>(); map.put("title", "G2"); map.put("info", "google 2"); map.put("img", R.drawable.i2); list.add(map); map = newHashMap<String, Object>(); map.put("title", "G3"); map.put("info", "google 3"); map.put("img", R.drawable.i3); list.add(map); returnlist; } // ListView 中某项被选中后的逻辑 @Override protectedvoidonListItemClick(ListView l, View v, intposition, longid) { Log.v("MyListView4-click", (String)mData.get(position).get("title")); } /** * listview中点击按键弹出对话框 */ publicvoidshowInfo(){ newAlertDialog.Builder(this) .setTitle("我的listview") .setMessage("介绍...") .setPositiveButton("确定", newDialogInterface.OnClickListener() { @Override publicvoidonClick(DialogInterface dialog, intwhich) { } }) .show(); } publicfinalclassViewHolder{ publicImageView img; publicTextView title; publicTextView info; publicButton viewBtn; } publicclassMyAdapter extendsBaseAdapter{ privateLayoutInflater mInflater; publicMyAdapter(Context context){ this.mInflater = LayoutInflater.from(context); } @Override publicintgetCount() { // TODO Auto-generated method stub returnmData.size(); } @Override publicObject getItem(intarg0) { // TODO Auto-generated method stub returnnull; } @Override publiclonggetItemId(intarg0) { // TODO Auto-generated method stub return0; } @Override publicView getView(intposition, View convertView, ViewGroup parent) { ViewHolder holder = null; if(convertView == null) { holder=newViewHolder(); convertView = mInflater.inflate(R.layout.vlist2, null); holder.img = (ImageView)convertView.findViewById(R.id.img); holder.title = (TextView)convertView.findViewById(R.id.title); holder.info = (TextView)convertView.findViewById(R.id.info); holder.viewBtn = (Button)convertView.findViewById(R.id.view_btn); convertView.setTag(holder); }else{ holder = (ViewHolder)convertView.getTag(); } holder.img.setBackgroundResource((Integer)mData.get(position).get("img")); holder.title.setText((String)mData.get(position).get("title")); holder.info.setText((String)mData.get(position).get("info")); holder.viewBtn.setOnClickListener(newView.OnClickListener() { @Override publicvoidonClick(View v) { showInfo(); } }); returnconvertView; } } }

更多相关文章

  1. android 3D gallery 并 判断当前选中项
  2. Android仿iPhone的日期时间选择器
  3. android 3D gallery 并 判断当前选中项
  4. android之AnologClock 和 DigitalClock
  5. Android简单的计算控件使用
  6. Android之Spinner用法
  7. android开关按钮,Switch,ToggleButton,RadioButton,CheckBox ,多种实
  8. android 自定义对话框宽不能占满父layout的解决办法
  9. Android自定义Dialog以控制其位置和宽高

随机推荐

  1. 【Android】 Android中适配器简介
  2. android studio debug签名设置
  3. Android 实现跳转到Google Play 详情页
  4. android打开联系人的代码
  5. android日期控件显示
  6. android java 检测文件夹(目录)是否存在,
  7. android获取控件宽高
  8. Android 自定义 LinearLayout
  9. Android 中颜色对应的值
  10. Android手机卫士(一)