0

I want to customize an EditText which should have "constants" like in the picture below, so that I get the minutes and the seconds. (the number interface is irrelevant).

gunr2171
  • 16,104
  • 25
  • 61
  • 88
mcjonesman
  • 27
  • 6

2 Answers2

1

Try by this code this code are here i have try by this code .This code is working .

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="vertical">  
<EditText 
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_marginTop="50dp" 
    android:textColor="#000000" 
    android:background="#CCCCCC"
    /> 
<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn0"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0" />

<Button
    android:id="@+id/btn1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="1" />

<Button
    android:id="@+id/btn2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="2" />
</LinearLayout>
 <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="3" />

<Button
    android:id="@+id/btn4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="4" />

<Button
    android:id="@+id/btn5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="5" />
</LinearLayout>
 <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    >
<Button
    android:id="@+id/btn6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="6" />

<Button
    android:id="@+id/btn7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="7" />

<Button
    android:id="@+id/btn8"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="8" />
</LinearLayout>

show here is image below here is pic below UI

Amitsharma
  • 1,577
  • 1
  • 17
  • 29
0

First of all, I see no EditText on the screen you posted, that's plain TextViews that are updating on clicking the numbers.

Anyway, you could use multiple TextViews/EditTexts, which would allow you to easily change their formatting as well, or you could programatically change the formatting yourself. If you want to have a string resource that accepts parameters see here on how to do that.

Community
  • 1
  • 1
Evripidis Drakos
  • 872
  • 1
  • 7
  • 15
  • But I want an dynamic EditText in which the "constants" should be skipped when you type some numbers. So that it should look like "0m00s" in the beginning and when you type for example first 1, then 2 and then 0 it should look like "1m20s". – mcjonesman May 08 '15 at 13:45
  • You should look up what an EditText actually is. This is not an EditText. You want a simple TextView. By clicking on a number (button) you will change the TextView's text according to your needs. You could either do this by recalculating the text based on its old value and the new one pressed, or keep a list with the numbers enetered so you can create the text each time from that list. – Evripidis Drakos May 08 '15 at 13:48
  • If you really do want an EditText and just want to keep some formating while you type into it, look into implementing a TextWatcher : http://stackoverflow.com/questions/18305520/edittext-custom-string-formatting – Evripidis Drakos May 08 '15 at 13:51