小编fap*_*soz的帖子

如何在 Activity 之外访问 findViewById()

我怎样才能通过 findViewById作为参数?

我想要创建方法:

public void makeText() {
    String random = randomize(); //example...
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(randomText);
}
Run Code Online (Sandbox Code Playgroud)

但是当然这个方法没有 function findViewById。方法makeText是外部ActivityFragment类。

java android

2
推荐指数
1
解决办法
2798
查看次数

标签 统计

android ×1

java ×1