to whl :
你好,謝謝您的回覆 我把程式碼給補上來
希望可以幫我解決一下
- public class bus_2ad extends BaseAdapter {
- public static int [] image={ R.drawable.a, R.drawable.b, R.drawable.c,R.drawable.d
- , R.drawable.e, R.drawable.f, R.drawable.g, R.drawable.h
- , R.drawable.i, R.drawable.j, R.drawable.k, R.drawable.l
- , R.drawable.m, R.drawable.n, R.drawable.o, R.drawable.p
- , R.drawable.q, R.drawable.r, R.drawable.s, R.drawable.t
- , R.drawable.u, R.drawable.v, R.drawable.w, R.drawable.x};
- public static String[] names= new String[bus_2.name.length];
- public static String[] sex= new String[bus_2.sex.length];
- public static int [] imgicon1 = {R.drawable.red};
- public static String[] th1 = new String[]{""};
- private LayoutInflater mInflater;
- private List<Map<String, Object>> mData;
- public static Map<Integer, Boolean> isSelected;
-
- public bus_2ad(Context context) {
- mInflater = LayoutInflater.from(context);
- init();
- }
- //初始化
- private void init() {
- mData = new ArrayList<Map<String,Object>>();
- for (int i=0; i<24; i++) {
- Map<String, Object> map = new HashMap<String, Object>();
- map.put("img",image[i]);
- map.put("imgicon", imgicon1[0]);
- map.put("title", names[i]);
- map.put("sex", sex[i]);
- map.put("th", "上車狀態:"+th1[0]);
- mData.add(map);
- }
- //定义isSelected这个map是记录每个listItem的状态,初始状态全部为false
- isSelected = new HashMap<Integer, Boolean>();
- for (int i=0; i<mData.size(); i++) {
- isSelected.put(i, false);
- }
- }
-
- public int getCount() {
- // TODO Auto-generated method stub
- return mData.size();
- }
-
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public long getItemId(int position) {
- // TODO Auto-generated method stub
- return 0;
- }
-
-
- public View getView(int position, View convertView, ViewGroup parent) {
- ViewHolder holder = null;
- //convertView为null的时候初始化convertView
- if (convertView == null) {
- holder = new ViewHolder();
- convertView = mInflater.inflate(R.layout.busout_2ad, null);
- holder.img = (ImageView)convertView.findViewById(R.id.img);
- holder.imgicon = (ImageView)convertView.findViewById(R.id.imgicon);
- holder.title = (TextView)convertView.findViewById(R.id.title);
- holder.sex = (TextView)convertView.findViewById(R.id.sex);
- holder.th = (TextView)convertView.findViewById(R.id.th);
- convertView.setTag(holder);
- } else {
- holder = (ViewHolder)convertView.getTag();
- }
- holder.img.setBackgroundResource((Integer)mData.get(position).get("img"));
- holder.imgicon.setBackgroundResource((Integer)mData.get(position).get("imgicon"));
- holder.title.setText(mData.get(position).get("title").toString());
- holder.sex.setText(mData.get(position).get("sex").toString());
- holder.th.setText(mData.get(position).get("th").toString());
- for(int i=0;i<names.length;i++)
- {
- if(bus_2.rs.equals(names[i]))
- {
-
- holder.imgicon.setImageResource(R.drawable.blue);
-
- }
- }
- return convertView;
- }
-
-
- public static final class ViewHolder {
- public ImageView img;
- public TextView title,sex,th;
- public static ImageView imgicon;
- int position;
- }
-
- }
複製代碼 |