如何获取列表视图中选择行的控件的ID [英] How to get widget ids of selected row of listview

查看:126
本文介绍了如何获取列表视图中选择行的控件的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是自定义列表视图中我application.In我行我有(两个图像,其余textviews)。

I am using an custom listview in my application.In my row I have (two images,remaining textviews).

当我点击的TextView之一,我想设置另一个TextView的data.I写道低于code做到这一点。

when I click on one of textview,I want to set another textview data.I wrote the code below to do this

     likes.setOnClickListener(new OnClickListener() {


        public void onClick(View v) {
//          if(likes.getText().toString().equals("Like")){
               TextView t=(TextView)v;
              TextView likesnumber1 = (TextView) findViewById(R.id.likesnumber);
//            TextView  likesnumber = (TextView) convertView.findViewById(R.id.likesnumber);
                int i=  Integer.parseInt(likescount.get(position));

           if(like_or_ulike.get(position).equals("Like")){
                Log.e("inlike","like");
                like_or_ulike.set(position, "Unlike");
                t.setText(like_or_ulike.get(position));
                UrltoValue.getValuefromUrl("https://graph.facebook.com/"+objectid.get(position)+"/likes?access_token="+accesstoken+"&method="+"post");
//             listView.getAdapter().getItemAt(position);
               j=i+1;
               String s=Integer.toString(j);
            likescount.set(position, s);
             likesnumber1.setText(likescount.get(position));

            }
            else{
                Log.e("unlike","unlike");
                like_or_ulike.set(position, "Like");
                t.setText(like_or_ulike.get(position));
                UrltoValue.getValuefromUrl("https://graph.facebook.com/"+objectid.get(position)+"/likes?access_token="+accesstoken+"&method="+"DELETE");

                   j=i-1;
                 String s=Integer.toString(j);
                likescount.set(position, s);
                 likesnumber1.setText(likescount.get(position));
            }
        }
    });

我怎样才能获得特定行的另一个TextView的ID当我点击textview.Is有可能获得该特定行的ID。

How can I get the another textview id of particular row when I click the textview.Is it possible to get the ids of that particular row.

推荐答案

当你想要得到的TextView的保持在同一行中,你可以做以下。

As you want to get hold of the textview in the same row, you can do the following.

与被点击的TextView中获得其母公司,然后使用你可以搜索你的TextView的parentview:

with the textview that was clicked get its parent and then using the parentview you can search for your textview:

View parent = (View) textViewThatWasClicked.getParent();
        if (parent != null) {
            TextView textViewThatYouWantToChange = parent.findViewById(R.id.textViewThatYouWantToChange);
            textViewThatYouWantToChange.setText(...);
        }

您将需要更改你寻找到你有其他的TextView的ID的ID。如果您需要设置一个id你可以在你使用的XML布局文件做到这一点。

you will need to change the id that you look for to the id you have for that other textview. If you need to set an id you can do this in the xml layout file you used.

我不能按照你的code不够好,实际上给你code但这应该足以让你在正确的方向。

I cant follow your code well enough to actually give you the code but this should be enough to get you in the right direction.

这篇关于如何获取列表视图中选择行的控件的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆