简体   繁体   English

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

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

I am working on the task that change the image resources on list view item by clicking on that image which is in list view item[ not click on list view item ]. 我正在通过单击列表视图项中的图像 [ 而不单击列表视图项 ]来更改列表视图项上的图像资源的任务。 It is like highlight the list view item using image resources. 就像使用图像资源突出显示列表视图项一样。 I here by submit my Base adapter class code. 我在这里通过提交我的Base适配器类代码。

DashListAdapter: DashListAdapter:

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);


        }
    }


}

the above code while click on the dashHolder.bookmark_img the image resource has to change from default image and respective Book mark API implementation also there for Book mark result update to server. dashHolder.bookmark_img上单击以上代码后,图像资源必须从默认图像更改,并且相应的Bookmark API实现也在那里,以将Bookmark结果更新到服务器。 In my code there is problem with changing image. 在我的代码中,更改图像存在问题。 kindly please look on my code and suggest me to get the solution. 请查看我的代码并建议我获取解决方案。 Thanks in advance for your time and consideration. 预先感谢您的时间和考虑。

You are not changing the model data so update it from 您没有更改模型数据,因此可以从更新

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM