0

I'm new to Java and Android Studio. How can I use this line of code in my program? I can't use casting anymore in API 26.

public <T extends View > T findViewById(int id)

enter image description here

VikaS GuttE
  • 1,636
  • 2
  • 14
  • 38
Hamza
  • 17
  • 1
  • 7

2 Answers2

1

It's not an error - now you don't have to cast your views into the type(like casting to editText). If before you had to do :

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

You don't need it anymore and you can just do this :

 editText = findViewById(R.id.id);
Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
0

So if your compileSdk is at least 26, that means no need to typeCast the EditText. You can simply use:

 EditText editText = findViewById(R.id.my_edittext);
Kavita Patil
  • 1,784
  • 1
  • 17
  • 30
  • the problem remains the same, can you just tell me how can i use public T findViewById(int id) in my code? i'm just a beginner sorry :( – Hamza Mar 02 '19 at 10:26
  • @Hamza, you can directly use `editText = findViewById(R.id.my_edittext);` no need to typecast with any view. The error which you are getting is `not the error` it is just the `warning`. You can remove the warning just by writing `editText = findViewById(R.id.my_edittext);` – Kavita Patil Mar 02 '19 at 10:31