I want to get the spinner selected value and return it as string to store in sqlite database read the data when needed.
I try the method as below,
sp = (Spinner) findViewById(R.id.spnCategory);
ArrayAdapter<CharSequence> ar = ArrayAdapter.createFromResource(this,
R.array.category, android.R.layout.simple_list_item_1);
ar.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
sp.setAdapter(ar);
String selection = sp.getSelectedItem().toString();
and get the string extras as below:
selection = extras.getString("category");
put extras as below:
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(context,ViewItem.class).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("category", category);
}
});
But I can't get the spinner value that selected, what I get just the first value in Spinner, may I know what wrong with my coding?