[android]代码库
/**
* 焦点图适配器
* @author xmz
*
*/
public class FocusAdapter extends BaseAdapter {
private List<Map<String,Object>> list;
private Context context;
public FocusAdapter(Context context){
list=new ArrayList<Map<String, Object>>();
this.context=context;
}
public int getCount() {
return list.size();
}
public Map getItem(int position) {
return list.get(position);
}
public long getItemId(int position) {
return position;
}
public void addFocus(Map<String, Object> map){
list.add(map);
notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
View view=LayoutInflater.from(context).inflate(R.layout.focus,null);
Map<String,Object> map=getItem(position);
//焦点图
RelativeLayout mainLayout=(RelativeLayout)view.findViewById(R.id.focus_mainLayout);
mainLayout.setBackgroundResource(Integer.parseInt(map.get("focusImage").toString()));
//影片说明
TextView introText=(TextView)view.findViewById(R.id.focus_introText);
introText.setText(map.get("intro").toString());
//焦点指针
ImageView pointImage=(ImageView)view.findViewById(R.id.focus_pointImage);
int resid=0;
switch (position){
case 0:
resid=R.drawable.focus_point_1;
break;
case 1:
resid=R.drawable.focus_point_2;
break;
case 2:
resid=R.drawable.focus_point_3;
break;
case 3:
resid=R.drawable.focus_point_4;
break;
case 4:
resid=R.drawable.focus_point_5;
break;
}
pointImage.setBackgroundResource(resid);
return view;
}
}
[源代码打包下载]