java - 安卓 : Does accessing view in nested layout takes time?

标签 java android

我在 Rood 布局中多次使用相同的布局。现在我正在访问嵌套布局中的 View ,如下所示。时间长吗。有没有更好的解决办法。

 TextView tv=(TextView)findViewById(R.id.fragment_forcast).findViewById(R.id.horizontalScrollView).
                findViewById(R.id.liner_layout).findViewById(R.id.forcas_layout_1).findViewById(R.id.day_field)

更新:这是我的方法:

private void populateForcastView(){
    TextView tv;
    View rootView=(View)findViewById(R.id.fragment_forcast).findViewById(R.id.horizontalScrollView).
            findViewById(R.id.liner_layout);

    for(int forcastFragmentIndex=1; forcastFragmentIndex<=3; forcastFragmentIndex++){
        int forcastFragmentId=getResources().getIdentifier("forcast_layout_" + forcastFragmentIndex, "id", getPackageName());
        tv=(TextView)rootView.findViewById(forcastFragmentId).findViewById(R.id.day_field);
        tv.setText("Sunday");
    }
}

最佳答案

是的,使用 Butterknife 库。

https://jakewharton.github.io/butterknife/

关于java - 安卓 : Does accessing view in nested layout takes time?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37631986/

相关文章:

Java MouseAdapter 没有响应

java - 在 Android 模拟器上创建 UDP 连接

java - 将 setText 设置为 EditText 时出现 NullPointerException - onDateSet

java - Servlet 回复 getHttpConnection

java - Android Studio说静态字段将泄漏上下文

android - Dagger - 如何在服务和 fragment 之间共享提供的对象?

java - 循环依赖设计

java - Selenium Connection Reset : Unable to find an exact match for CDP version 96, 所以返回找到的最接近的版本:95

android - Android 上的 IP 地址存储在哪里?

android - 有人知道让 AT&T 的无线代理在 45 秒后不超时的方法吗?