我一直在研究注册表单应用程序,其中使用了很少的微调器小部件.微调器用于选择国家,州和城市.因此,这些微调器需要以某种方式相互连接(下面的代码将显示我是如何尝试实现的).
表格代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true">
<TextView
android:text="Student Registration Form"
android:textSize="22sp"
android:textAlignment="center"
android:layout_marginBottom="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/country_spinner"
android:foregroundTint="#222"
android:background="#001c47"
android:layout_marginBottom="20dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/state_spinner"
android:foregroundTint="#222"
android:background="#001c47"
android:layout_marginBottom="20dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city_spinner"
android:foregroundTint="#222"
android:background="#001c47"
android:layout_marginBottom="20dp" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
上面的代码有更多的小部件,你可以在java文件中找到它们; 我没有将它们包含在上面的代码中,因为它会使它太长.
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.SharedPreferences;
import android.nfc.Tag;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import …Run Code Online (Sandbox Code Playgroud)