开发者

Access components within my custom view (inflated layout)?

开发者 https://www.devze.com 2023-04-04 06:15 出处:网络
I\'m probably making some silly mistake. I have a custom view and use LayoutInflater to get the layout from an XML.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号