开发者

How to access a TextView / an ImageView in a ListView-child element at X position..?

I want to access the child of a ListView at position x. The ListView has the following xml layout code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:orientation="horizontal"
         android:layout_width="fill_parent"
         android:layout_height="40dp"
         android:background="@drawable/bg_grad_iled">
    <ImageView 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:id="@+id/iv_icon" />
    <TextView android:id="@+id/tv_name"
        android:textColor="@color/kategorieTextColor"
        android:layout_height="40dp"
        android:textSize="16sp"
        android:layout_weight=".50"
        android:layout_width="0dip"
        android:padding="3px" 
        android:layout_marginLeft="8px"/&开发者_StackOverflow中文版gt;
    <TextView android:id="@+id/tv_comment"
        android:textColor="@color/kategorieTextColor"
        android:layout_height="40dp"
        android:textSize="16sp"
        android:layout_weight=".20"
        android:layout_width="0dip"
        android:padding="3px"/>
    <TextView android:id="@+id/tv_distance"
        android:textColor="@color/kategorieTextColor"
        android:layout_height="40dp"
        android:textSize="16sp"
        android:layout_weight=".30"
        android:layout_width="0dip"
        android:padding="3px"/>
</LinearLayout>

How can I access, (e.g.) the textview 'tv_name' in the 5th child of the ListView? Thats my current listener:

lv1.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Toast.makeText(context, "Clicked", 1000).show();
                }
              });

Perhaps the adapter I use may be important? Refer this


when you click on the list item OnItemClickListener will return the view, so that you can get access through that view ..

Eg:

if you want to get text of tv_name at position 5 simply:



 public void onItemClick(AdapterView<?> arg0, View v, final int position,long arg3) 
                {
                 TextView text=(TextView)v.findViewById(R.id.tv_name);
                 Toast.makeText(this, text.getText(), Toast.LENGTH_LONG).show();

                             }
                  });

try it and get me the feedback

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜