开发者

Access components within my custom view (inflated layout)?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜