Note that there are some explanatory texts on larger screens.

plurals
  1. POSpinner not working in android,
    primarykey
    data
    text
    <p>I have made a simple demo for spinners in android,In that 2 activities are there in first activity a simple spinner and in second a textView.So when any item fromthe spinner is selected it will be displayed on the second Activity,i have tried the following code but its not working:</p> <p><strong>Activity1.java</strong></p> <pre><code>package com.example.sppiner; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.SimpleAdapter; import android.widget.Spinner; public class MainActivity extends Activity { Spinner sp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sp=(Spinner)findViewById(R.id.spinner1); String[] s={"ahmedabad","baroda","chitor","daman","england","france","georgia"}; sp.setAdapter(new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item,s)); sp.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub String n = (String)arg0.getItemAtPosition(arg2); Intent i =new Intent(MainActivity.this,Act2.class); Bundle b =new Bundle(); i.putExtra("nat", n); startActivity(i); } }); } } </code></pre> <p><strong>act2.java</strong></p> <pre><code> package com.example.sppiner; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.widget.TextView; public class Act2 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_act2); TextView tv =(TextView)findViewById(R.id.tv1); Bundle b = getIntent().getExtras(); Intent i =getIntent(); String nat = b.getString("nat"); tv.setText(nat); } } </code></pre> <p>Please help me...thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload