Reputation: 137
i want a close button at the end of AutoCompleteTextView so that on click of that button it clears the AutoCompleteTextView. It shouldn't be a button, but something like 'X' mark at the end of AutoCompleteTextView but inside it.Is that possible in android?
Upvotes: 0
Views: 590
Reputation: 8695
I've had the same problem but with edittext. Here is my desicion:
<RelativeLayout
android:layout_height="55dip"
android:layout_width="fill_parent">
<EditText
android:id="@+id/search"
android:layout_width="fill_parent"
android:layout_marginLeft="7dip"
android:layout_marginRight="7dip"
android:layout_height="40dip"
android:paddingRight="50dip"
android:paddingLeft="5dip"
android:layout_centerVertical="true">
</EditText>
<LinearLayout
android:layout_width="47dip"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:gravity="right|center_vertical">
<ImageButton
android:layout_height="20dip"
android:layout_width="21dip"
android:background="@drawable/some_bg"
android:layout_marginRight="10dip">
</ImageButton>
</LinearLayout>
</RelativeLayout>
You can place a TextView instead of ImageButton in my example.
Upvotes: 2
Reputation: 1006674
You can put the 'X' inside the AutoCompleteTextView
with android:drawableRight
, I think. However, finding out if the user clicks on it would be tricky. You might be able to create your own subclass of AutoCompleteTextView
where you override onTouchEvent()
and if the event is over your 'X', handle it yourself instead of chaining to the superclass. I have not tried any of this, though, so YMMV.
Upvotes: 2