-1

I wanted to use an editText with the type number.
If you use this, it doesn´t work:

    Number editText = (Number) v.findViewById(R.id.editText);

The error is at

Number editText = (Number) v.findViewById(R.id.editText);

It says:

Inconvertible types; cannot cast android.view.View to java.lang.Number

The solution is easy (thanks to @Ehsan for the helpful answer):

Edittext editText = (Edittext) v.findViewById(R.id.editText);

Cyb3rKo
  • 385
  • 5
  • 21

2 Answers2

5

The type in XML is EditText not Number so use Editext as

EditText editText = (EditText) v.findViewById(R.id.editText);

For Number use inputType

android:inputType="number" 

e.g

<EditText
    android:id="@+id/editText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="number" />

You can also use android:digits to use specific digit(s)

Pavneet_Singh
  • 35,963
  • 5
  • 49
  • 64
3

You are casting your Edittext to a Number

Number editText = (Number) v.findViewById(R.id.editText);

Replace it with:

Edittext editText = (Edittext) v.findViewById(R.id.editText);
Ehsan
  • 2,430
  • 5
  • 25
  • 50