我正在处理更改列表视图项上的图像资源的任务,方法是点击该图像,这是列表视图项[不点击列表视图项 ]。这就像使用图像资源突出显示列表视图项一样。 我在这里提交我的Base适配器类代码。
public class DashListAdapter extends BaseAdapter {
public static ProgressDialog progress;
public static ListView dashListView;
Context c;
/* String fromdate_formated = "";
String todate_formated = "";*/
private LayoutInflater inflater;
private List<DashListModel> dashRowList;
public DashListAdapter(Context c, List<DashListModel> dashRowList, ListView dashListView) {
this.c = c;
this.progress = new ProgressDialog(c);
this.dashListView = dashListView;
this.dashRowList = dashRowList;
}
public DashListAdapter(Context c, List<DashListModel> dashRowList) {
this.c = c;
this.progress = new ProgressDialog(c);
this.dashRowList = dashRowList;
}
/* public DashListAdapter(){
}*/
@Override
public int getCount() {
Log.e("size()", "size------>" + dashRowList.size());
return this.dashRowList.size();
}
@Override
public Object getItem(int position) {
return dashRowList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder dashHolder;
if (inflater == null)
inflater = (LayoutInflater) c
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.dashboard_jobdetails_list, null);
Log.e("get pos", "get pooooossss---->" + dashRowList.get(position));
final DashListModel dashModel = dashRowList.get(position);
dashHolder = new ViewHolder(convertView);
dashHolder.bookmark_img.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (dashModel.getDashIsBookmarked().equalsIgnoreCase("0")) {
Log.e("imgchange", " imgchange");
dashHolder.bookmark_img.setImageResource(R.drawable.bookmark);
Map<String, String> params = new HashMap<String, String>();
params.put("candidate_id", SessionStores.getBullHornId(c));
params.put("joborder_id", dashModel.getDashId());
//new BookMarkTaskAdd(c, params);
notifyDataSetChanged();
}
if (dashModel.getDashIsBookmarked().equalsIgnoreCase("1")) {
Log.e("imgchange", " imgchange");
dashHolder.bookmark_img.setImageResource(R.drawable.blue_tag_img);
Map<String, String> params = new HashMap<String, String>();
params.put("candidate_id", SessionStores.getBullHornId(c));
params.put("joborder_id", dashModel.getDashId());
// new BookMarkTaskDelete(c, params);
notifyDataSetChanged();
}
}
});
dashHolder.dash_company_name.setText(dashModel.getDashCompanyName());
dashHolder.dash_position_name.setText(dashModel.getDashJobPosition());
dashHolder.dash_posted_date.setText(dashModel.getPostedDate());
dashHolder.dash_job_description.setText(dashModel.getDashJobDescription());
dashHolder.dash_salary.setText(dashModel.getDashSalary() + " - " + dashModel.getDashEndSalary());
dashHolder.dash_available_date.setText(dashModel.getFromDate() + " - " + dashModel.getEndDate());
dashHolder.book_jobCity.setText(dashModel.getDashJobCity());
Log.e("BookMa", " Book!!!!!!!!!!!!!!!" + dashModel.getDashIsBookmarked());
if (dashModel.getDashIsBookmarked().equalsIgnoreCase("1")) {
Log.e("BookMark 1", " BookMaerk 1");
dashHolder.bookmark_img.setImageResource(R.drawable.bookmark);
} else if (dashModel.getDashIsBookmarked().equalsIgnoreCase("0")) {
Log.e("BookMark 00", " BookMaerk 00");
dashHolder.bookmark_img.setImageResource(R.drawable.blue_tag_img);
}
return convertView;
}
static class ViewHolder {
@Bind(R.id.book_company_name)
TextView dash_company_name;
@Bind(R.id.book_position_name)
TextView dash_position_name;
@Bind(R.id.book_posted_date)
TextView dash_posted_date;
@Bind(R.id.book_job_description)
TextView dash_job_description;
@Bind(R.id.book_salary)
TextView dash_salary;
@Bind(R.id.book_available_date)
TextView dash_available_date;
@Bind(R.id.book_jobCity)
TextView book_jobCity;
/* @Bind(R.id.book_jobState)
TextView book_jobState;*/
@Bind(R.id.sideView)
ImageView sideView;
@Bind(R.id.bookmark_img)
ImageView bookmark_img;
@Bind(R.id.noificationLayout)
RelativeLayout noificationLayout;
@Bind(R.id.notificationCount)
TextView notificationCount;
private RelativeLayout.LayoutParams viewLayParams;
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
以上代码,同时点击 dashHolder.bookmark_img ,图片资源必须更改默认图片和相应的 书签API实施 也可以将书签结果更新到服务器。在我的代码中,更改图像存在问题。请注意我的代码,并建议我得到解决方案。提前感谢您的时间和考虑。