how to get id in different layout

后端 未结 5 1950
無奈伤痛
無奈伤痛 2020-12-30 14:52

i have id \"@+id/call\" in single_item.xml when i use findVewById it (the layout setcontextview(R.layout.main)) .the ap

5条回答
  •  不思量自难忘°
    2020-12-30 15:37

    If you want to access a view in another layout (not the active layout), then you can inflate the layout you want to use and access it that way.

    Example:

    View inflatedView = getLayoutInflater().inflate(R.layout.other_layout, null);
    TextView text = (TextView) inflatedView.findViewById(R.id.text_view);
    text.setText("Hello!");
    

    More information about inflating layouts can be found here.

提交回复
热议问题