I Use the follow code . and OK . > Log.d(TAG,"this.getPaddingRight(): " + this.getPaddingRight()); > Log.d(TAG,"this.getPaddingTop(): "+this.getPaddingTop()); > Log.d(TAG,"this.getHeight(): " + this.getHeight()); > Log.d(TAG,"this.getPaddingBottom(): " + this.getPaddingBottom());
2011/4/23 Sunil Lakhiyani <[email protected]> > Hello Developers, > > I have one Edit Text with right drawable. > The xml code is > > <TextView android:id="@+id/trip_txt_to" > android:layout_width="wrap_content" android:layout_height="wrap_content" > android:text="@string/addname" android:layout_alignParentLeft="true" > android:textStyle="bold" android:textColor="@color/black" > android:typeface="normal" android:padding="10dp" > android:layout_below="@+id/lineview1" /> > > <test.ui.CustomEditTextActivity > android:id="@+id/nameofpersonr" android:layout_height="wrap_content" > android:hint="@string/hint" > android:layout_toRightOf="@+id/name" android:textColor="@color/black" > android:typeface="normal" > android:layout_below="@+id/lineview1" > android:drawableRight="@drawable/icon" > android:layout_width="180dp"> > </test.ui.CustomEditTextActivity > > <ImageView android:id="@+id/clearnameimage" > android:layout_alignParentRight="true" > android:layout_width="wrap_content" > android:layout_height="wrap_content" android:scaleType="fitXY" > android:layout_below="@+id/lineview1" > android:src="@drawable/deleteicon" android:padding="5dp"/> > > > and CustomEditTextActivity.java > > public class CustomEditTextActivity extends EditText { > private Drawable rightSideDrawable; > private Rect rectangleBounds; > > public CustomEditTextActivity(Context context, AttributeSet attributeSet, > int defStyle) { > > super(context, attributeSet, defStyle); > } > > public CustomEditTextActivity(Context context, AttributeSet attributeSet) { > super(context, attributeSet); > } > > public CustomEditTextActivity(Context context) { > super(context); > } > > @Override > public void setCompoundDrawables(Drawable left, Drawable top, > Drawable right, Drawable bottom) { > if (right != null) { > rightSideDrawable = right; > } > super.setCompoundDrawables(left, top, right, bottom); > } > > @Override > protected void finalize() throws Throwable { > rightSideDrawable = null; > rectangleBounds = null; > super.finalize(); > } > > public Rect getRectBound() { > return rectangleBounds; > } > > public Drawable getRightDrawable() { > return rightSideDrawable; > } > // on touch event code i got from some site.. > @Override > public boolean onTouchEvent(MotionEvent event) > { > > if(event.getAction() == MotionEvent.ACTION_UP && > rightSideDrawable!=null) > { > rectangleBounds = rightSideDrawable.getBounds(); > final int x = (int)event.getX(); > final int y = (int)event.getY(); > > if(x>=(this.getRight()-rectangleBounds.width()) && > x<=(this.getRight()-this.getPaddingRight()) > && y>=this.getPaddingTop() && > y<=(this.getHeight()-this.getPaddingBottom())) > { > this.setText(""); > event.setAction(MotionEvent.ACTION_CANCEL);//use this to > prevent the keyboard from coming up > } > } > return super.onTouchEvent(event); > } > > } > > Now problem is, > > when i open the activity, it shows me keyboard and i can right in edit > text, but as soon as i touch to edit text it launches another activity, i > called it "InfoActivity.java". But InfoActivity.java is supposed to be > launched if I click on drawable not on edit text. > Can you please help me to get click event or touch event on right hand side > drawable, instead of edit text? or is there any other alternative way? > Also, because of this i can not use this line for keyboard.. > > > this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); > > > Can anyone help me in that? I have made lots of changes in ontouch event > written above but fail. > > So please help me in that. I really appreciate it. Thank you in advance. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- - Protect your dream ... -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

