-1

If I use findViewById like this(first code) then I can't use same id(usernameid) in different layout:

username = (EditText) findViewById(R.id.usernameid);

Is there any way to use like this (second code)? :

username = (EditText) findViewById(R.layout.activity-signup.id.usernameid);
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Musa
  • 1
  • 1
  • As a matter of fact you can use same ID in different layouts .. See https://stackoverflow.com/questions/12333624/can-i-use-the-same-id-in-different-layout-in-android. – ADM Mar 27 '19 at 04:01
  • Possible duplicate of [Can I use the same id in different layout in Android?](https://stackoverflow.com/questions/12333624/can-i-use-the-same-id-in-different-layout-in-android) – ADM Mar 27 '19 at 04:01

2 Answers2

2

In Android you cant assign an View to layout with defined ID liked this

username = (EditText) findViewById(R.layout.activity-signup.id.usernameid);

the only way is passing EditText to EditText Id.

Kishan Viramgama
  • 893
  • 1
  • 11
  • 23
Ankit Tale
  • 1,924
  • 4
  • 17
  • 30
0

In java file layout id of layout is already added in java file.

ATIQ UR REHMAN
  • 431
  • 3
  • 12