问题: 使用 api 让我正在使用的应用程序变得复杂。api 调用包括将 api 的响应处理成一个 listView,如下所示:
因此,对于 listView 中的这种类型的布局,需要一个自定义(ArrayList)适配器,其代码如下:
public class ArrayListAdapter extends BaseAdapter{
public Context mContext;
public LayoutInflater mInflater;
public ArrayList<HashMap<String,String>> mData;
private SparseBooleanArray mSelectedItemsIds;
public ArrayListAdapter(Context context, ArrayList<HashMap<String,String>> data){
mSelectedItemsIds = new SparseBooleanArray();
mData = data;
this.mContext = context;
mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mData.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder vh;
if(convertView == null){
vh = new ViewHolder();
convertView = mInflater.inflate(R.layout.projectlist_frame, null);
vh.projectTitle = (TextView)convertView.findViewById(R.id.projecttitle);
vh.projectSector = (TextView)convertView.findViewById(R.id.projectsector);
vh.cb = (CheckBox)convertView.findViewById(R.id.checkBox1);
convertView.setTag(vh);
} else{
vh = (ViewHolder)convertView.getTag();
}
vh.projectTitle.setText(mData.get(position).get("title").toString());
vh.projectSector.setText(mData.get(position).get("sector").toString());
return convertView;
}
class ViewHolder{
TextView projectTitle, projectSector;
CheckBox cb;
}
}
需要帮助
该复选框现在是生成一个ActionMode
检查。参考了很多材料,我意识到需要为此设置一个自定义适配器。那么如何实现两个适配器?还是有其他方法??请帮忙!