4

I have a button and a listView. When user selects any item in list, i should update the button text with the item name and X at the end. When user clicks on the updated button, i am updating the list and change the button text to the default text. I am trying to achieve this by adding android:ellipsize="middle" to the button xml but it is not working. Ref: What does ellipsize mean in android?

<Button
    android:id="@+id/actor_selected"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/thetake_orange"
    android:textColor="@color/white_color"
    android:layout_toRightOf="@id/seperator"
    android:layout_margin="5dp"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    />

SOLUTION I got this working.

    <Button
    android:id="@+id/actor_selected"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/thetake_orange"
    android:textColor="@color/white_color"
    android:drawableRight="@drawable/abc_ic_clear_mtrl_alpha"
    android:layout_toRightOf="@id/seperator"
    android:layout_margin="5dp"
    android:paddingLeft="2dip"
    android:paddingRight="2dip"
    android:singleLine="true"
    android:ellipsize="middle"
    />
Community
  • 1
  • 1
  • Ellipsize us used to scroll text automatically when text is beyond your view. instead of using ellipsize try to use android gravity middle for button layout. – gkondati Apr 28 '15 at 20:52
  • Thanks Ganga. I tried with android:gravity="center" and android:layout_gravity="center" but both didn't work. I tried with different values i didn't see any changes. – androidbeginner Apr 28 '15 at 21:08
  • 1
    Worked when i used android:singleLine="true" and android:ellipsize="middle. How to Show **X** always at the end. If the text has just two characters, i still need to put **X** at the end. – androidbeginner Apr 28 '15 at 21:20
  • In that case its better to use two textviews , one for start , another one at the right. Because if you use space or any other techniques that will only work on one resolution. It will fail in multi resolution . – gkondati Apr 28 '15 at 21:32
  • @GangaNaidu Thats right. Thank you. I updated the question with my working code. – androidbeginner Apr 29 '15 at 20:35

0 Answers0