Change the text format of the switch and get a list of all countries and put it in Android spinner

Hi below is a screenshot containing a list of details to fill in by the user. Since you can see that the gender selection switches do not match the rest of the text in action. This is a bold text. I would like to make it look like the remaining text in action, how can I do this?

In addition, instead of the user entering the name of the state and country, I would like to provide a list of all countries in the spinner, and depending on the country selected by the state, the counter should be filled with the cities of the selected country. How can i do this?

enter image description here

Below is my xml code for the above activity

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".RegisterActivity" >

<TextView
    android:id="@+id/textView6"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/topic"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:text="@string/full_name" />

<EditText
    android:id="@+id/fname"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPersonName" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/email" />

<EditText
    android:id="@+id/email"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textEmailAddress" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/age" />

<EditText
    android:id="@+id/age"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="number" />

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RadioButton
        android:id="@+id/radioMale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_male" />
    <RadioButton
        android:id="@+id/radioFemale"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/radio_female" />
</LinearLayout>

<TextView
    android:id="@+id/textView4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/postal_address" />

<EditText
    android:id="@+id/address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPostalAddress" />

<TextView
    android:id="@+id/textView5"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/state" />

<EditText
    android:id="@+id/state"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textCapWords" />

<TextView
    android:id="@+id/textView7"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/country" />

<EditText
    android:id="@+id/country"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textCapWords" />

<Button
    android:id="@+id/done"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/done" />

+4
3

android:textAppearance="?android:attr/textAppearanceSmall"

+2
+1

Q2 strings.xml string-array ArrayAdapter .

  • ArrayAdapter spinner
  • spinner.
  • array
  • spinner setOnItemSelectedListener spinner

ArrayAdapter<CharSequence> countryArray, statesArray;
countryArray = ArrayAdapter.createFromResource(this,R.array.countries,android.R.layout.simple_spinner_item);
countryArray            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

statesArray = ArrayAdapter.createFromResource(this, R.array.states,android.R.layout.simple_spinner_item);
statesArray.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

countrySpinner.setAdapter(countryArray);
        specialitySpinner.setOnItemSelectedListener(this);
stateSpinner.setAdapter(stateArray);
        specialitySpinner.setOnItemSelectedListener(this);
public void onItemSelected(AdapterView<?> parent, View view, int position,
            long id) {
switch (parent.getId()) {
country= (String) parent.getItemAtPosition(position);
case R.id.country_spinner:
switch (position) {
case 0:
statesArray = ArrayAdapter.createFromResource(this,
                        R.array.country1states,
                        android.R.layout.simple_spinner_item);
                stateSpinner.setAdapter(statesArray);
break;
case 1:
statesArray = ArrayAdapter.createFromResource(this,
                        R.array.country2states,
                        android.R.layout.simple_spinner_item);
                stateSpinner.setAdapter(statesArray);
break;
}

Q1 android:textAppearance="?android:attr/textAppearanceSmall"

Pay attention to Here I wrote this code, therefore we expect errors. Please make changes to the appropriate code.

+1
source

Source: https://habr.com/ru/post/1532609/


All Articles