Saturday, February 22, 2014

Get the spinner selected value android


/ / Bind data to store
ArrayAdapter shop_adapter = new ArrayAdapter (FirstLoginActivity.this, android.R.layout.simple_spinner_item, shopList);
shop_adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); / / style
spinnershop.setAdapter (shop_adapter);
spinnershop.setOnItemSelectedListener (new OnItemSelectedListener () {
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
/ / Spinner spinner = (Spinner) arg0;
/ / Shopname = (String) spinner.getItemAtPosition (arg2);
shopname = arg0.getItemAtPosition (arg2). toString () ;/ / delivery stores
. ((Declare) getApplication ()) setShopname (shopname);
/ / Arg0.setVisibility (View.VISIBLE);
System.out.println ("store:" + shopname);
}
public void onNothingSelected (AdapterView arg0) {

}
});

/ / Bind the data to the reservoir
final ArrayAdapter positon_adapter = ArrayAdapter.createFromResource (this, R.array.position, android.R.layout.simple_spinner_item);
positon_adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
spinnerposition.setAdapter (positon_adapter);
spinnerposition.setOnItemSelectedListener (new OnItemSelectedListener () {
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
/ / Get the selected address
position = spinnerposition.getSelectedItem (). toString () ;/ / pass Reservoir
. ((Declare) getApplication ()) setPosition (position);
arg0.setVisibility (View.VISIBLE);
System.out.println ("Reservoir:". + Spinnerposition.getSelectedItem () toString ());

}
public void onNothingSelected (AdapterView arg0) {
selectpositon.setText ("You have no choice reservoir");
}
});
/ / To select or choose Duitou shelves binding data
final ArrayAdapter shelfheap_adapter = ArrayAdapter.createFromResource (this, R.array.shelfheap, android.R.layout.simple_spinner_item);
spinnershelfheap.setAdapter (shelfheap_adapter);
spinnershelfheap.setOnItemSelectedListener (new OnItemSelectedListener () {
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
shelfheap = FirstLoginActivity.this.getResources () getStringArray (R.array.shelfheap) [arg2] toString ();..
((Declare) getApplication ()). SetShelfheap (shelfheap) ;/ / select inventory objects are Duitou or shelf
arg0.setVisibility (View.VISIBLE);
System.out.println ("Duitou or shelves:". + Spinnershelfheap.getSelectedItem () toString ());
if (shelfheap.equals ("shelf"))
{

spinnershop.setOnItemSelectedListener (itemSelectedListener);
}
if (shelfheap.equals ("Duitou"))
{
selectHeapno ();
}
}
public void onNothingSelected (AdapterView arg0) {
selectshelf.setText ("You do not choose to be on the shelf or Duitou inventory");
}
});

/ / Set the Cancel button listener
cancelbutton.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
/ / End of the current activity
finish ();
}
});
/ / Set the login button listener
loginbutton.setOnClickListener (new OnClickListener () {
@ Override
public void onClick (View v) {
String username = useredittext.getText (). ToString () ;/ / job number
String pwdpwd = pwdedittext.getText () toString ();.

database1 = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
/ / Query to get the cursor
/ / String sql = "select * from User where username = '" + uname + "' and userno = '" + password + "'";
Cursor c = database1.rawQuery ("?? Select * from t_user where username = and userno =", new String [] {username.toString (), pwdpwd.toString ()});
if (c.moveToFirst ())
{
/ / Start the activity
/ / String shopname = ((Declare) getApplicationContext ()). GetShopname () ;/ / stores pass over
/ / String position = ((Declare) getApplicationContext ()). GetPosition () ;/ / Reservoir pass over
/ / String shelfheap = ((Declare) getApplicationContext ()). GetShelfno () ;/ / stack top shelf number or pass over
if (username.equals ("") | | pwdpwd.equals ("") | | shopname.equals ("") | | position.equals ("") | | shelfheap.equals (""))
{
showDialog ("Please select after reopening inventory");
return;
}
Intent intent = new Intent (FirstLoginActivity.this, FirstInActivity.class);
startActivity (intent);
}
else
{
showDialog ("Enter the user number does not work, please try again!");
}




}
});


}



protected void selectHeapno () {
/ / TODO Auto-generated method stub

final ArrayAdapter heapno_adapter = ArrayAdapter.createFromResource (this, R.array.heapno, android.R.layout.simple_spinner_item);
spinnershelf.setAdapter (heapno_adapter);
spinnershelf.setOnItemSelectedListener (new OnItemSelectedListener () {
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
heapno = FirstLoginActivity.this.getResources () getStringArray (R.array.heapno) [arg2] toString ();.. / / If inventory Duitou, pass the stack top
((Declare) getApplication ()). SetShelfno (heapno) ;/ / pass heap top
arg0.setVisibility (View.VISIBLE);
System.out.println ("stack top shelf number:". + Spinnershelf.getSelectedItem () toString ());

}
public void onNothingSelected (AdapterView arg0) {

}
});
}



String selShop = null;
/ / Select the store shelves linkage corresponding number
private OnItemSelectedListener itemSelectedListener = new OnItemSelectedListener () {

/ / Find
store shelves under the number corresponding number from the store shelves table

@ Override
public void onItemSelected (AdapterView parent, View view,
int position, long id) {
Spinner spShop = (Spinner) parent;
selShop = (String) spShop.getItemAtPosition (position);

Map data = (Map) shopData.get (position) ;/ / get the corresponding selected based on id and then get shelf
int pid = data.get (selShop) ;/ / get id
storesList shelfList = ShopDB.getCityByPid (pid);
ArrayAdapter shelf_adapter = new ArrayAdapter (FirstLoginActivity.this, android.R.layout.simple_spinner_item, shelfList);
shelf_adapter
. SetDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
spinnershelf.setAdapter (shelf_adapter);
spinnershelf.setOnItemSelectedListener (citySelectedListener);

}
@ Override
public void onNothingSelected (AdapterView parent) {
/ / TODO Auto-generated method stub

}
};

String selectedShop = null;
private OnItemSelectedListener citySelectedListener = new OnItemSelectedListener () {
@ Override
public void onItemSelected (AdapterView parent, View view,
int position, long id) {
Spinner spShelf = (Spinner) parent;
heapno = spinnershelf.getSelectedItem (). toString () ;/ / delivery stores
((Declare) getApplication ()) setShelfno (heapno);.
selectedShop = (String) spShelf.getItemAtPosition (position);

System.out.println ("pile number one:". + Spinnershelf.getSelectedItem () toString ());


}

@ Override
public void onNothingSelected (AdapterView parent) {
/ / TODO Auto-generated method stub

}
};

In another activity in,
String shopname = ((Declare) getApplicationContext ()). GetShopname () ;/ / stores pass over
String position = ((Declare) getApplicationContext ()). GetPosition () ;/ / Reservoir pass over
String shelfheap = ((Declare) getApplicationContext ()). GetShelfno () ;/ / stack top shelf number or pass over
tvnotify.setText ("stores is:" + shopname + "Reservoir is:" + position + "shelf number is:" + shelfheap);
The results appear shopname no matter what I choose the spinner, always defaults to the value of the first item in the dropdown list, you master over here, really do not understand this thing a spinner, seeking advice.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Code is a mess, but it should be OnItemSelectedListener () inside wrong, check it yourself, provided you an idea to check it,
 d = (Spinner) findViewById (R.id. spinner1); 
ArrayAdapter adapter = ArrayAdapter.createFromResource (this, R.array.roompath, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
d.setAdapter (adapter);
d.setPrompt ("shop address");
d.setOnItemSelectedListener (new OnItemSelectedListener () {

@ Override
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
/ / TODO Auto-generated method stub
roompath = String.valueOf (arg2) ;/ / this is to get the value
}

Reply:
Then after you get the value refers to the choice of the first few, and then pay the appropriate value for arg2, Friendly reminder written on the outside event oh.

Reply:
cited a floor heaimnmn reply:
code is a mess, but it should be OnItemSelectedListener () inside wrong, check it yourself, provided you an idea Go check it,
 d = (Spinner) findViewById (R.id.spinner1); 
ArrayAdapter adapter = ArrayAdapter.createFromResource (this, R.array.roompath, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
d.setAdapter (adapter);
d.setPrompt ("shop address");
d.setOnItemSelectedListener (new OnItemSelectedListener () {

@ Override
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
/ / TODO Auto-generated method stub
roompath = String.valueOf (arg2) ;/ / this is to get the value
}

My store is to read the code from the database, Friendly reminder written on the outside event oh. Weak weak ask, what is written on the outside event oh? Gets the value of the selected item is it? Thank you
Reply:
cited a floor heaimnmn reply:
code is a mess, but it should be OnItemSelectedListener () inside wrong, check it yourself, provided you an idea Go check it,
 d = (Spinner) findViewById (R.id.spinner1); 
ArrayAdapter adapter = ArrayAdapter.createFromResource (this, R.array.roompath, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item);
d.setAdapter (adapter);
d.setPrompt ("shop address");
d.setOnItemSelectedListener (new OnItemSelectedListener () {

@ Override
public void onItemSelected (AdapterView arg0, View arg1,
int arg2, long arg3) {
/ / TODO Auto-generated method stub
roompath = String.valueOf (arg2) ;/ / this is to get the value
}


Indeed OnItemSelectedListener () wrong, mainly stores spinner wrote two OnItemSelectedListener (). Thank you, the users answer. Of all to you.

No comments:

Post a Comment