【发布时间】:2018-12-05 09:22:55
【问题描述】:
我有一个膨胀布局的代码:
mainLayout = findViewById(R.id.mainLayout);
addNewMed.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addNewMed.startAnimation(AnimationUtils.loadAnimation(MedicationAdd.this, R.anim.rotate_complete));
v = LayoutInflater.from(MedicationAdd.this).inflate(R.layout.medication_poles, null);
mesurement = v.findViewById(R.id.mesurement);
mainLayout.addView(v);
}
});
当我想从medication_poles 找到我的微调器mesurement 时,我遇到了一个空错误
medication_poles.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/medPole"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="8dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Время приема"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Препарат"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Дозировка"/>
<Spinner
android:id="@+id/mesurement"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
如何从膨胀布局中找到对象?
【问题讨论】:
-
发帖
res/layout/medication_poles.xml -
查看问题,刷新
标签: java android android-inflate