Access components within my custom view (inflated layout)?
-
28-10-2019 - |
문제
I'm probably making some silly mistake.
I have a custom view and use LayoutInflater to get the layout from an XML. Now , say I have a button called bt1. Normally , I would use findViewById , but that isn't working.
How do I get the button INSIDE that custom view?
LinearLayout lytContainer;
public obj(Context c){
super(c);
lytContainer = (LinearLayout) View.inflate(
this.getContext(), R.layout.myLayout, null);
TextView t = (TextView)findViewById(R.id.bt1);
t.setText("cake");
}
해결책
You have to use:
TextView t = (TextView)lytContainer.findViewById(R.id.bt1);
제휴하지 않습니다 StackOverflow