문제

I have many many ImageButtons,

and i want to use something to shortcut the code.

Like use findViewById method with a String value same findViewById("R.id.btn_name"),

or get button by tag,

or something like this.

Thanks in Advance.

도움이 되었습니까?

해결책

You could do something like:

int resourceId = this.getResources().getIdentifier("btn_name", "id", this.getPackageName());

where this refers to the context/activity. Then use it as follows:

ImageButton imageButton = (ImageButton) findViewById(resourceId);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top