Я сделал один макет в Android Studio и сделал Java-класс (form_view.java) для его кодирования, но он не работает.
Вот мой Java-код (form_view.java)
public form_view(Activity activity, int Layoutid){
this.activity=activity;
LayoutFormInfo = activity.<LinearLayout>findViewById(R.id.Layoutid);
init();
}
private void init() {
e1=LayoutFormInfo.findViewById(R.id.editText);
e2=LayoutFormInfo.findViewById(R.id.editText2);
e3=LayoutFormInfo.findViewById(R.id.editText3);
b1=LayoutFormInfo.findViewById(R.id.button);
ch1=LayoutFormInfo.findViewById(R.id.checkBox);
b1.setOnClickListener(this);
e3.setText("hello");
}
@Override
public void onClick(View v) {
if(v.getId()== R.id.button){
Toast.makeText(activity, "21+ only, keep out", Toast.LENGTH_SHORT).show();
}
}
}
и я включаю свой макет по этому коду в основной вид деятельности
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/yes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:layout_editor_absoluteX="54dp"
tools:layout_editor_absoluteY="44dp"/>
<include layout="@layout/ayoutid"
/>
<include layout="@layout/ayoutid"
android:id="@+id/Layoutid"/>
</androidx.constraintlayout.widget.ConstraintLayout>