문제

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top