问题
I am making for spinner controls with fragment of multiple and first fragment show spinner properly and after then second fragment call then i set on default spinner not set plz help me, thanks in advance
String[] strArraySpinner = { "Existing Customer ?", "New Customer ?" };
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (mSpinner.getSelectedItem().toString().equalsIgnoreCase(strArraySpinner[0])) {
Toast toast = Toast.makeText(mContext, "Item= " + mSpinner.getSelectedItem().toString(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else if (mSpinner.getSelectedItem().toString().equalsIgnoreCase(strArraySpinner[1])) {
Toast toast = Toast.makeText(mContext, "Item= " + mSpinner.getSelectedItem().toString(), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
And second fragment calls when i m selection method on spinner call and this is not working,
mSpinner.setSelection(); // here i m set on default spinner with prompt
回答1:
I found for my self solution as mSpinner.setSelection();
method remove and set again spinner of adapter calling,
mSpinner.setAdapter(new SpinnerBaseAdapter(mContext, strArraySpinner);
This is working fine and change for each an every items inside of dropdown and get the results.
来源:https://stackoverflow.com/questions/17991756/how-to-set-prompt-value-on-setselection-on-spinner-in-android