Byron's log
‹‹ back
Android 关于 BaseAdapter的继承。
Create Time : 2011-06-07 16:11:20
Modify Time : 2011-06-09 08:55:19
最近在blog上贴的代码越来越多,而blog一直没有完成wiki语法功能,导致标签经常错乱,要排期优先解决这事儿了。

class UpdateAdapter extends BaseAdapter{

	ArrayList<HashMap<String,Object>> data;
	LayoutInflater inflater;
	Context appContext;
	
	public UpdateAdapter(Context c,ArrayList<HashMap<String,Object>> tdata){
		this.inflater = LayoutInflater.from(c);
		this.data = tdata;
		this.appContext = c;
	}

	public int getCount(){
		return data.size();
	}

	public Object getItem(int position){
		return data.get(position);
	}

	public long getItemId(int position){
		return position;
	}
	
	
	public View getView(int position,View convertView, ViewGroup parent){
		final View view = inflater.inflate(R.layout.list_update,null);
		TextView txtTitle = (TextView) view.findViewById(R.id.update_title);
		TextView txtContent = (TextView) view.findViewById(R.id.update_content);
		ImageView imgType = (ImageView) view.findViewById(R.id.update_type);
		ImageView actFave = (ImageView) view.findViewById(R.id.action_fave);
		
		txtTitle.setText(data.get(position).get("title").toString());
		txtContent.setText(data.get(position).get("content").toString());
		imgType.setImageResource(Integer.parseInt(data.get(position).get("type").toString()));
		
		actFave.setTag(position);
		actFave.setOnClickListener(new View.OnClickListener(){
			public void onClick(View v){
				int position = Integer.parseInt(v.getTag().toString());
				((ImageView)v).setImageResource(R.drawable.action_fave_02);
				
				Toast.makeText(appContext,v.getTag().toString(),Toast.LENGTH_SHORT).show();
			}
		});

		return view;
	}
}