开发者

Android: extract the string of the TextView in the list

Following is my listview layout. Now I have a image and textview in my listview. I want to extract the content of the textview and show it in the Toast.

<?xml version="1.0" encoding="UT开发者_如何转开发F-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="#E6E7E2">
    <ImageView android:id="@+id/Thumbnail" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:src="@drawable/icon" />
    <TextView android:id="@+id/FilePath" android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:textColor="#000"/>
</LinearLayout>

Usual way is not working and application crashing when I'm trying like this

// on click lister for list view
        lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                String sdcarduri = (((TextView) arg1).getText()).toString();
                //Toast.makeText(AndroidThumbnailList.this, "BEEEEEEE", 2000).show();


            }

        });


use this code

    lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                TextView tv=(TextView)arg1.findViewById(R.id.FilePath);
String sdcardUri=tv.getText().toString();
                //Toast.makeText(AndroidThumbnailList.this, "BEEEEEEE", 2000).show();


            }

        });


@Override
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
LinearLayout layout = (LinearLayout) arg1;
TextView v = (TextView) layout.getChildAt(1);
 String sdcarduri =v.getText().toString();

Toast.makeText(AndroidThumbnailList.this, v.getText().toString(), 2000).show();


            }

        });
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜