4

Hi below is the screen shot of an activity containing a list of details for user to fill in. As u can see the choose gender radio buttons do not match with rest of the text in the activity. They are kind of bold text. I would like to make it similar to remaining text in activity how can I do it?

Also instead of having the user to type the state and country name I would like to provide the list of all countries in a spinner and depending on the country selected the state spinner should be populated with cities of the country selected. 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" />

ik024
  • 3,566
  • 7
  • 38
  • 61

3 Answers3

2

Try android:textAppearance="?android:attr/textAppearanceSmall" for each or your radio button

k3v1n4ud3
  • 2,904
  • 1
  • 15
  • 19
  • Thanks man :) Now the radio button text size is same as the the rest of text in activity but its still a little bold how to make it in a normal text? – ik024 Mar 20 '14 at 07:30
  • May be I shud jst change the text color to greyish :P – ik024 Mar 20 '14 at 07:30
  • Also anything on my second question. Fetching the list of all countries and states of respective countries??? – ik024 Mar 20 '14 at 07:31
  • For the country spinner, you can follow http://developer.android.com/guide/topics/ui/controls/spinner.html, and for the state spinner, I think the best way is to populate it in the onItemSelected callback from the first spinner. If you want everything to be defined in xml you can have a look into array of arrays in resources: http://stackoverflow.com/questions/4326037/android-resource-array-of-arrays – k3v1n4ud3 Mar 20 '14 at 08:31
1

Answer 1: If you want same size, you can try this in your XML for RadioButton: "android:textColor="#404040" "

Answer 2: Good Examples are here: http://androidexample.com/Spinner_Basics_-_Android_Example/index.php?view=article_discription&aid=82&aaid=105

mazy
  • 11
  • 3
  • Thanks for the help man :) The link u provided in ans 2 tells us how to create a spinner which I am aware of. My question is from wer do I fetch the data of all countries and how. – ik024 Mar 20 '14 at 07:38
1

Q2 You need to store countries and states in your strings.xml as string-array and get values from there and populate your ArrayAdapter accordingly. Here is how

  1. Populate your ArrayAdapter from the countries array and populate your country spinner
  2. Get the country from first spinner.
  3. Get your states from the state array accordingly
  4. Populate your state spinner in the setOnItemSelectedListener of the country spinner

Example

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 use android:textAppearance="?android:attr/textAppearanceSmall"

Please note I have written this code here, so expect errors. Please modify the code accordingly.

Atif Farrukh
  • 2,219
  • 2
  • 25
  • 47