2011-08-09 3 views
0

GestureOverlayView에서 하위 요소로 TextView를 가져 오려고합니다. 여기 Android의 GestureOverlayView에서 하위 항목 가져 오기

내보기 XML 코드 :

<RelativeLayout android:layout_width="fill_parent" android:id="@+id/relativeLayout1" android:layout_height="wrap_content"> 
    <android.gesture.GestureOverlayView android:layout_height="wrap_content" android:id="@+id/gestureOverlayView1" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_alignParentLeft="true"> 
     <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:id="@+id/linearLayout2" android:layout_height="wrap_content"> 
      <LinearLayout android:orientation="horizontal" android:weightSum="1" android:layout_width="260dp" android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:baselineAligned="false" android:layout_weight="0.32"> 
       <CheckBox android:id="@+id/sListCheckbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="0.32"></CheckBox> 
       <TextView android:text="TextView" android:id="@+id/sListText" android:layout_width="212dp" android:ems="15" android:layout_gravity="center" android:textAppearance="?android:attr/textAppearanceLarge" android:singleLine="true" android:layout_height="wrap_content" android:layout_weight="0.32"></TextView> 
      </LinearLayout> 
      <ImageView android:paddingRight="0dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="0.32" android:id="@+id/imageView1" android:src="@drawable/searchbutton"></ImageView> 
     </LinearLayout> 
    </android.gesture.GestureOverlayView> 
</RelativeLayout> 

그리고 난 같은 텍스트 뷰에 도달하려고하지만 난

adapterLine.gestureOverlayView.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 

if (gestureDetector.onTouchEvent(event)) { 

    RelativeLayout llt = (RelativeLayout) v.getParent(); 
    TextView childText = (TextView) llt.getChildAt(4); 
+0

프로그램이 충돌하는 행은 무엇입니까? 예외/오류 로그를 게시 할 수 있습니까? 내 생각 엔 당신이 올바른 부모보기를 얻지 못한다는 것입니다. 코드를 게시하십시오 v. – Jack

+0

null을 반환하는 childText – cagryInside

답변

0

나는 내가 내 목록보기에 내 모션 이벤트 리스너에서

TextView childText = (TextView)findViewById(R.id.sListText); 

이 내가 무엇입니까 G로보기를 사용할 수 없습니다이

RelativeLayout llt = (RelativeLayout) v.getParent(); 
GestureOverlayView gow = (GestureOverlayView) llt.getChildAt(0); 
LinearLayout ll1 = (LinearLayout) gow.getChildAt(0); 
LinearLayout ll2 = (LinearLayout) ll1.getChildAt(0); 
TextView childText = (TextView) ll2.getChildAt(1); 

를 사용하여 내 문제를 해결하고 난 몰라 정확히 어떤 textview가 반환됩니다.

+0

gestureOverlayview가 당신을 위해 일하는 것을 잊지 않습니까? 나는 그것을 작동시킬 수 없다. – Sarvesh

1

당신은 호출하는 RelativeLayout의의 LLT = (RelativeLayout의) childText에 NullPointerException이 무엇입니까 v.getParent(); -> 변수가 LinearLayout에 대해 llt라고 말하면 이지만 RelativeLayout을 얻고 있습니까? 이 시도 :

LinearLayout ll = (LinearLayout)findViewById(R.id.linearLayout1); 
TextView childText = (TextView)ll.getChildAt(1); // it may be 2 depending on if the root is 0 or not, cant remember 

이 사실은 왜 그냥하지 :

TextView childText = (TextView)findViewById(R.id.sListText); 

?

+0

이 문제가 해결 되었습니까? – Jack

관련 문제