问题描述
因此,我遇到一个问题,即我有一个具有4个选项1-4的微调器,而我有4个TextInputLayout
,现在我想要实现的是从片段开始,我想要我的textinputlayout
被隐藏。当我单击微调器并选择第一个选项时,只有一个TextInputLayout
应该可见。当我选择2个选项时,我需要2 TextInputLayout
可见,依此类推。现在的问题是我的TextInputLayout
仍然不可见,我提供了switch
的情况,其中选择了1,然后使TextInputLayout
可见,但它不起作用。任何帮助将不胜感激
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Choose Number of vehicle and quantity"
android:layout_marginLeft="12dp"/>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:background="@drawable/spinner_border"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/VehicleNoText1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:hint="Vehicle No"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:imeOptions="actionNext"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/QuantityText1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Quantity"
android:layout_marginTop="16dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/VehicleNoText2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Vehicle No"
android:layout_marginTop="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:imeOptions="actionNext"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/QuantityText2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Quantity"
android:layout_marginTop="16dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/VehicleNoText3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Vehicle No"
android:layout_marginTop="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:imeOptions="actionNext"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/QuantityText3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Quantity"
android:layout_marginTop="16dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/VehicleNoText4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Vehicle No"
android:layout_marginTop="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:imeOptions="actionNext"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/QuantityText4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="Quantity"
android:layout_marginTop="16dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="12dp"
android:layout_weight="0.5"
android:visibility="invisible"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:inputType="text"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的片段类
List < String > categories = new ArrayList < > ();
categories.add("1");
categories.add("2");
categories.add("3");
categories.add("4");
ArrayAdapter < String > dataAdapter = new ArrayAdapter < > (this.getActivity(),android.R.layout.simple_spinner_item,categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
vehicleSelector.setAdapter(dataAdapter);
vehicleSelector.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView << ? > adapterView,View view,int i,long l) {
String selectedItem = adapterView.getItemAtPosition(i).toString();
Log.i("Values",selectedItem);
switch (selectedItem) {
case "1":
c13.getEditText().setVisibility(View.VISIBLE);
Objects.requireNonNull(c14.getEditText()).setVisibility(View.VISIBLE);
break;
case "2":
Objects.requireNonNull(c13.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c14.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c15.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c16.getEditText()).setVisibility(View.VISIBLE);
break;
case "3":
Objects.requireNonNull(c13.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c14.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c15.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c16.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c17.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c18.getEditText()).setVisibility(View.VISIBLE);
break;
case "4":
Objects.requireNonNull(c13.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c14.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c15.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c16.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c17.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c18.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c19.getEditText()).setVisibility(View.VISIBLE);
Objects.requireNonNull(c20.getEditText()).setVisibility(View.VISIBLE);
break;
}
}
@Override
public void onNothingSelected(AdapterView << ? > adapterView) {
}
});
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)