Open main XML layout and drop Spinner widget or paste below code:
</LinearLayout>
Now open Your Java File and paste below code:
Now Run your code...
<LinearLayout xmlns:android="http://schemas. android.com/apk/res/android"
android:layout_width="fill_ parent"
android:layout_height="fill_ parent"
android:orientation="vertical"
>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_ parent"
android:layout_height="wrap_ content" />
Now open Your Java File and paste below code:
package sel.listG; //package name
import
android.os.Bundle;
import
android.view.View;
import
android.widget.AdapterView;
import
android.widget.AdapterView. OnItemSelectedListener;
import
android.widget.ArrayAdapter;
import
android.widget.Spinner;
import
android.widget.Toast;
import
android.app.Activity;
public class MainActivity extends Activity implements
OnItemSelectedListener {
String values[]={"Select
One","January", "July", "June", "Ravi", "Ravinder", "Abhishek", "Abhinav", "Harkishore", "Hardev"};
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate( savedInstanceState);
setContentView(R.layout.activi ty_main);
Spinner
lv=(Spinner)findViewById(R.id. spinner1);
ArrayAdapter<?>
adapter=new ArrayAdapter<String>(this, android.R.layout.simple_ spinner_item, values);
//you can left the below one line because it is merging two layout
adapter. setDropDownViewResource( android.R.layout.simple_ spinner_dropdown_item);
lv.setAdapter(adapter);
lv.setOnItemSelectedListener(t his);
}
@Override
public void
onItemSelected(AdapterView<?> a, View v, int pos,long id)
{
Toast.makeText( getApplicationContext(),a. getItemAtPosition(pos)+" Selected", Toast.LENGTH_SHORT).show();
}
@Override
public void
onNothingSelected(AdapterView< ?> arg0) {
// TODO
Auto-generated method stub
}
}
Now Run your code...
As/a mohsin.i want to get he screen size at runtime. Can u plz help me
ReplyDeletew/a ..like this app https://play.google.com/store/apps/details?id=helper.plus ?
Deletecheck information page and than screen property.
Thanks for replying me.actually i want that every andriod mob support my app having diferrent width 'height.i used defferent methods for it but showing some error..can u plz help me brother?
ReplyDeleteFor this, android gives us multiple folders facility for putting xml according to density. Don't use any method.
DeleteHow can i use this brother?
ReplyDeleteI have button on the top of which i have a te.xtview.the height of button changes on every click but the textview goes here and there.now i want to change the position of textview with the change of hight of bttn.can u plz help me brother
ReplyDeletesir ,could you plz upload source code for spinner with multiple selection option populate from mysql php??
ReplyDelete