如何在单击 baseadapter 中的列表视图项时更新文本

How to Update the Text on click of list view items in baseadapter

我是 android 的新手,我遇到了这个问题,我有一个文本可以计算点赞数,单击点赞将在文本 view.what 代码中设置点赞总数写入以在点击喜欢时增加 holder.likestatus。请帮助我....我搜索了 3 天但没有得到确切的答案。

这是基本适配器

    public View getView(final int position, View convertView, final ViewGroup parent) {
            // Declare Variables
          //  TextView rank;
          //  TextView country;
            TextView likestat = null;
              if(convertView==null){
                  LayoutInflater inflater = ((Activity) context).getLayoutInflater();
                  convertView = inflater.inflate(R.layout.feed_item, null);
                  holder=new ViewHolder();
                  pos=getItemViewType(position);
                  holder.name = (TextView) convertView.findViewById(R.id.name);

                  holder.status=(TextView)convertView.findViewById(R.id.txtStatusMsg);
                  holder.userimage=(ImageView)convertView.findViewById(R.id.profilePic);
                  holder.postimage=(ImageView)convertView.findViewById(R.id.feedImage1);
                  holder.like=(TextView)convertView.findViewById(R.id.like);
                //  likestat=(TextView)convertView.findViewById(R.id.likecount);
                  holder.likestatus=(TextView)convertView.findViewById(R.id.likecount);
                  holder.comment=(TextView)convertView.findViewById(R.id.comment);
                  holder.commentstatus=(TextView)convertView.findViewById(R.id.commentcount);
                  holder.pos=position;

                  convertView.setTag(holder);
              }
              else {
                holder = (ViewHolder) convertView.getTag();
            }
              holder.like.setTag(pos);

       holder.comment.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                feedid=data.get(position).get("TempFeed_id");
                openDialog();
                new Comment().execute();
            }
        });
       holder.postimage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                  feedimage=data.get(position).get("TempPost_Image");
                  feedimagediaload();
            }
        });

         /*   View itemView = inflater.inflate(R.layout.viewitem, parent, false);*/
            // Get the position
            resultp = data.get(position);
            String count=resultp.get("TempLike");
            holder.likestatus.setText(resultp.get("TempLike"));
            holder.comment.setText("Comment"+" "+resultp.get("TempCommnt"));
            holder.commentstatus.setText(resultp.get("TempCommnt"));
            // Locate the TextViews in listview_item.xml
            holder.name.setText(resultp.get("TempFirstName"));

            String status=resultp.get("Temp_Status");

           holder.like.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    feedid=data.get(position).get("TempFeed_id");
                    String pos=data.get(position).get("TempLike");
                    int c=Integer.parseInt(pos);
                       c++;
                       pos=c+"";

                     holder.likestatus.setText(pos);
                     ****// no increment on the like
                     //what code i have to written here****

                    new likepost().execute();
                    //here i call execute method to like the post



                }
            });

How to Update the Text on click of list view items in baseadapter

默认情况下 TextView 不可点击,因此请确保使用 xml

中的 android:clickable="true" 属性设置 TextView 可点击

increment the holder.likestatus on click of like:

更新 likestatus TextView 如同 like 按钮点击:

holder.like.setOnClickListener(new OnClickListener() {

@Override
   public void onClick(View v) {
   //...your code here....        

   ViewGroup viewGroup=(ViewGroup)v.getParent();
   // access likecount TextView from feed_item layout
   TextView txtLikeStatus=(TextView)viewGroup.findViewById(R.id.likecount);
   txtLikeStatus.setText(String.valueOf(pos));

   }
});

像点击一样更新,如果这不起作用,请告诉我,从下面的代码打印日志值。

holder.like.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                feedid=data.get(position).get("TempFeed_id");
                String likeCount=data.get(position).get("TempLike");

                Log.i("likeCount", likeCount);

                int counter=Integer.valueOf(likeCount)+1;                

                Log.i("counter", counter);

                 holder.likestatus.setText(counter+"");

                new likepost().execute();
                //here i call execute method to like the post



            }
        });