如何通过单击列表项右上角的图像来更改列表视图项图像资源?

How to change the list view item image resources by click on the right corner image on list item?

我正在处理通过单击列表视图项中的图像更改列表视图项上的图像资源的任务[不单击列表视图项目]。这就像使用图像资源突出显示列表视图项。 我在这里提交我的 Base 适配器 class 代码。

DashList 适配器:

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 图片资源必须从默认图片和相应的 Book mark API implementation 也用于将 Book mark 结果更新到服务器。在我的代码中,更改图像有问题。请查看我的代码并建议我获得解决方案。预先感谢您的时间和考虑。

您没有更改模型数据,因此从

更新它
            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();
            }

To

            if (dashModel.getDashIsBookmarked().equalsIgnoreCase("0")) {
                dashModel.setDashIsBookmarked("1");
                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")) {
                dashModel.setDashIsBookmarked("0");
                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();
            }