0

次のような LIstView アイテムの行のレイアウトがあります。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:descendantFocusability="afterDescendants"
    android:gravity="right"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:gravity="right"
        android:textSize="40sp" 
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:focusable="false"  />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@drawable/btn_background" >

        <Button
            android:id="@+id/share_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="2dp"
            android:background="@drawable/delete_btn"
            android:drawableRight="@drawable/delete"
            android:paddingBottom="3dp"
            android:paddingTop="2dp"
            android:text="share"
            android:onClick="myClickHandler" />

    </RelativeLayout>

</LinearLayout>

そして、ユーザーが(myClickHandler()メソッドで)削除ボタンをクリックしたときにTextViewのテキストを取得したいのですが、

このコードで:

RelativeLayout vwParentRow = (RelativeLayout)v.getParent();

Button(RelativeLayout) の親を取得しますが、Button の親の親にある TextView のテキストを取得する方法がわかりません

どうすればこれを行うことができますか?

ありがとう

4

4 に答える 4

3

myClickHandler()メソッドでこれを試してください

RelativeLayout vwParentRow = (RelativeLayout)v.getParent();
LinearLayout vwGrandParentRow = (LinearLayout)vwParentRow.getParent();

TextView yourTV=(TextView)vwGrandParentRow.findViewByid(R.id.label);

Log.i("Text",yourTV.getText().toString());
于 2013-08-13T09:34:46.917 に答える
0
TextView yourTextView = (TextView )v.getParent().getParent().findViewById(R.id.label)
String yourText = yourTextView.getText().toString(); 
于 2013-08-13T09:34:53.097 に答える
0

それは動作するはずです

  TextView textviewDate=(TextView)findViewById(R.id.label);
  String selectedText=textviewDate.getText().toString();
于 2013-08-13T09:54:25.173 に答える