1.

Use the same scenario of “Contact Us“screen and one more functionality therefor make a call. Can you please write code to make a call for a specific mobile number.

Answer»

We need to create two Spinner control for our activity name as State and COUNTRY. This spinner control will display from the ADAPTER. State spinner adapter CHANGES depending on County spinner adapter. 

I have written below code to displaying data in Adapter . Please find below step for displaying spinner control:

  • Add values for countries and state.
<string-array name="country_array"> <item>India</item> <item>Pakisthan</item> <item>Sri Lanka</item> </string-array> <string-array name="state_india"> <item>Maharasta</item> <item>TamilNadu</item> <item>Delhi</item> <item>Madhya PRADESH</item> </string-array>
  • Add two Spinner control in layout_xml file.
  • In activity.java class  file we will create object for Adapter and Spinner.
SpinnerCountry = (Spinner) findViewById(R.id.spinnerCountry); spinnerState = (Spinner) findViewById(R.id.spinnerState); spinnerCountry.setOnItemSelectedListener(this); @Override public VOID onItemSelected(AdapterView<?> parent, View arg1, int pos, long arg3) { parent.getItemAtPosition(pos); if (pos == 0) { ArrayAdapter<CharSequence> adapter = ArrayAdapter .createFromResource(this, R.array.state_india, android.R.layout.simple_spinner_item); spinnerCity.setAdapter(adapter); } else if (pos == 1) { ArrayAdapter<CharSequence> adapter = ArrayAdapter .createFromResource(this, R.array.state_pakisthan, android.R.layout.simple_spinner_item); spinnerCity.setAdapter(adapter); } else if (pos == 2) { ArrayAdapter<CharSequence> adapter = ArrayAdapter .createFromResource(this, R.array.state_srilanka, android.R.layout.simple_spinner_item); spinnerCity.setAdapter(adapter);


Discussion

No Comment Found

Related InterviewSolutions