Getting child from GestureOverlayView in Android
I am trying to get TextView as a child element from GestureOverlayView.
here is my view xml code :
<RelativeLayout android:layout_width="fill_parent" android:id="@+id/relativeLayout1" and开发者_开发技巧roid: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>
And i am trying to reach TextView like this but i am getting nullPointerException on childText
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);
You are calling RelativeLayout llt = (RelativeLayout)v.getParent(); --> your variable says llt for LinearLayout, but you are getting a RelativeLayout? Try this:
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
Actually why not just do this:
TextView childText = (TextView)findViewById(R.id.sListText);
?
I have solved my problem by using this
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);
i cannot use
TextView childText = (TextView)findViewById(R.id.sListText);
this because i am getting v view from my motion event listener on my list view and i do not know exactly which textview is returning.
精彩评论