android get id of view

Solutions on MaxInterview for android get id of view by the best coders in the world

showing results for - "android get id of view"
Liam
10 Jul 2020
1//Don't get the ID name/string from the view ID.
2
3//Instead use the 
4android:tag = "String"
5//in your xml 
6
7//Then in Java use 
8View.getTag()
9  
10//To still get the ID name/string from view ID.
11getResources().getResourceEntryName(View.getId())
Marc
15 Feb 2020
1public void onClick(View v) {
2    switch (v.getId()) {
3    case R.id.add_04:
4        Toast.makeText(MainActivity.this, "1", Toast.LENGTH_LONG).show();
5        break;
6    case R.id.add_05:
7        Toast.makeText(MainActivity.this, "2", Toast.LENGTH_LONG).show();
8        break;
9    }
10}