Tag: 布局充气器

TextView Null膨胀父布局后

TextView Null膨胀父布局后。 我正在运行一个循环,这膨胀了一些这些布局: for(i in ticketAr?.indices!!){ var inf1:LayoutInflater = LayoutInflater.from(context) var infv:View = inf1.inflate(R.layout.ticket_individual,null,false) infv.setId(parseInt(ticketAr[i].string("ntb_id"))) var thetitle = infv.tck_event_title thetitle.setText(ticketAr[i].string("age_group_desc")) } 堆栈跟踪 10-25 09:30:35.839 11549-11549/com.example.xx.listview E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.xx.listview, PID: 11549 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.xx.listview.Ordering_Setup$getData$1.invoke(Ordering_Setup.kt:145) at com.example.xx.listview.Ordering_Setup$getData$1.invoke(Ordering_Setup.kt:29) at com.github.kittinunf.fuel.core.DeserializableKt$response$1.invoke(Deserializable.kt:37) at com.github.kittinunf.fuel.core.DeserializableKt$response$1.invoke(Deserializable.kt) at […]

拦截每个视图元素被膨胀?

我试图拦截在我的活动中正在充气的每个视图窗口小部件,并覆盖该视图的setText功能(如果存在)。 所以,如果一个TextView在XML布局中有一个android:text =“bla”,我希望能够截取这个,并且可能会在xml中设置的所有文本的末尾添加一个**。 似乎接近我需要的一种方法是使用自定义布局充气器。 LayoutInflaterCompat.setFactory(layoutInflator, InflatorOnSteriods(this)) 并在我的InflatorOnSteriods重写onCreateView,然后拦截所有视图..这种方法似乎并没有工作。 onCreateView永远不会被调用。 我也试过使用cloneInContext LayoutInflaterCompat.setFactory(layoutInflater.cloneInContext(this), InflatorOnSteriods(this)) 但是也没有运气,也许我的方法是完全错误的,我也打开了一个不同的方式,我可以截取所有呈现的视图,并具体设置一个特定的观点。 确保我将是最后一个改变视图并确保系统尊重我的更改并且不会在以后覆盖它们是非常重要的。 更新: 虽然我不认为它相关; 代码InflatorOnSteroids.kt class InflatorOnSteriods(val appCompatActivity: AppCompatActivity) : LayoutInflaterFactory { override fun onCreateView(parent: View, name: String, context: Context, attrs: AttributeSet): View { var result: View if (TextUtils.equals(name, "DebugDrawerLayout")) { result = ImageView(context, attrs) } result = appCompatActivity.onCreateView(name, context, attrs) if (result == […]