I have a spinner2 which will have day and month, when user select day, s1 and s2 will display hours and mins respectively.
On startup of the activity, I have the daily selected.
The problem is I keep on getting toast of daily. Which suggested that it gets selecteditem endlessly. Also, I cant select values in s1 and s2, the spinner keep on refreshing among themselves. How to solve this?
public class try_spinner extends Activity implements AdapterView.OnItemSelectedListener {
Spinner spinner1, spinner2, s1, s2, s3;
String app_name, room_name;
TextView app, room;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.try_spinner);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int) (width * .9), (int) (height * .7));
Bundle extras = getIntent().getExtras();
final String app_string = extras.getString("APPLIANCE_NAME");
final String room_string = extras.getString("APPLIANCE_ROOM");
app = (TextView) findViewById(R.id.app_name);
app.setText(app_string);
room = (TextView) findViewById(R.id.room_name);
room.setText(room_string);
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(this);
spinner2 = (Spinner) findViewById(R.id.spinner2);
s1 = (Spinner) findViewById(R.id.s1);
s2 = (Spinner) findViewById(R.id.s2);
s3 = (Spinner) findViewById(R.id.s3);
spinner2.setOnItemSelectedListener(this);
s1.setOnItemSelectedListener(this);
s2.setOnItemSelectedListener(this);
s3.setOnItemSelectedListener(this);
if (app_string.equals("Lighting")) {
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.lighting));
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.notifyDataSetChanged();
spinner1.setAdapter(dataAdapter2);
} else if (app_string.equals("Shower Heater")) {
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.shower_heater));
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.notifyDataSetChanged();
spinner1.setAdapter(dataAdapter2);
} else {
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.empty));
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.notifyDataSetChanged();
spinner1.setAdapter(dataAdapter2);
}
}
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
String txt_spinner2 = String.valueOf(spinner2.getSelectedItem());
Toast.makeText(this, txt_spinner2, Toast.LENGTH_SHORT).show();
if (txt_spinner2.contentEquals("Daily")) {
List<String> list = new ArrayList<String>();
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.days));
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter.notifyDataSetChanged();
s1.setAdapter(dataAdapter);
String txt_s1 = String.valueOf(s1.getSelectedItem());
//set for daily hours usage
List<String> list3 = new ArrayList<String>();
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.hours));
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter3.notifyDataSetChanged();
s2.setAdapter(dataAdapter3);
//set for daily minutes usage
List<String> list4 = new ArrayList<String>();
ArrayAdapter<String> dataAdapter4 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.hours));
dataAdapter4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter4.notifyDataSetChanged();
s2.setAdapter(dataAdapter4);
//set for daily empty thrd space
List<String> list5 = new ArrayList<String>();
ArrayAdapter<String> dataAdapter5 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.empty));
dataAdapter5.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter5.notifyDataSetChanged();
s3.setAdapter(dataAdapter5);
}
else if (txt_spinner2.contentEquals("Monthly")) {
List<String> list = new ArrayList<String>();
list.add("Conveyance");//you should add items from db here(2nd spinner)
list.add("the end");
ArrayAdapter<String> dataAdapter6 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter6.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter6.notifyDataSetChanged();
s3.setAdapter(dataAdapter6);
}
}
First of all set adapter first to spinner and then call setOnItemSelectedListener() for it. b'z when spinner value gets initialized it even call setOnItemSelectedListener method. you can put debugger and check.
Secondly always check for which spinner or widget you are getting event, in your case for spinner you can do like this
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
Spinner clickedSpinner = (Spinner) parent;
switch (clickedSpinner.getId()) {
case R.id.spinner1:
// your code for spinner1
String str = spinner1.getSelectedItem().toString();
break;
}
}
so change your code and see its working or not. hope it will help you...
Related
i have too spinners , spinner and spinner2, first one has a standard menu, the second must change relative to items from spinner.
am trying to get the position of item selected in spinner and then put it as a parametre into my method item2sp to change spinner's 2 items.
but i doesn't change, i keep getting only the first item menu in spinner2, how can i fix it help me please.
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
Spinner spinner2;
List<String> categories;
List<String> ndp;
List<String> ps;
ArrayAdapter<String> dataAdapter;
ArrayAdapter<String> ndpAdapter;
ArrayAdapter<String> psAdapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);
// Spinner Drop down elements
categories = new ArrayList<String>();
categories.add("NDP");
categories.add("PS");
categories.add("PA");
categories.add("PC");
categories.add("PH");
ps = new ArrayList<String>();
ps.add("AA");
ps.add("BB");
ps.add("CC");
ndp = new ArrayList<String>();
ndp.add("RP");
ndp.add("AFF");
ndp.add("RPA");
// Creating adapter for spinner
dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
psAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ps);
ndpAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ndp);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
psAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ndpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
}
public void itemsp2 (int position){
switch (position){
case 0:
spinner2.setAdapter(ndpAdapter);
Toast.makeText(getBaseContext(), ""+position, Toast.LENGTH_LONG).show();
break;
case 1:
spinner2.setAdapter(psAdapter);
Toast.makeText(getBaseContext(), ""+position, Toast.LENGTH_LONG).show();
break;
}
}
// int position = spinner.getSelectedItemPosition();
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// On selecting a spinner item
String item = parent.getItemAtPosition(position).toString();
itemsp2(position);
// Showing selected spinner item
// Toast.makeText(parent.getContext(), "Selected: " + item, Toast.LENGTH_LONG).show();
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
iller is my First List and I set this list my firs spinner then I implements onItemSelected method for this spinner. In this method you can add your second spinner with difrent List.
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
List<String> iller = new ArrayList<String>();
iller.add("İl Seçiniz..");
iller.add("Antalya");
iller.add("Burdur");
iller.add("Bursa");
iller.add("Balıkesir");
iller.add("Giresun");
iller.add("İstanbul");
ArrayAdapter<String> illerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, iller);
illerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(illerAdapter);
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner2.setVisibility(View.INVISIBLE);
editText = (EditText) findViewById(R.id.editText);
editText.setVisibility(View.INVISIBLE);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int itemId = (int) id;
if (itemId == 1) {
iller.remove("İl Seçiniz..");
antalyaİlceler = new ArrayList<String>();
antalyaİlceler.add("İlçe Seçiniz..");
antalyaİlceler.add("Konyaaltı");
antalyaİlceler.add("Muratpaşa");
antalyaİlceler.add("Alanya");
antalyaİlceler.add("Manavgat");
ArrayAdapter<String> antalyaİlcelerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, antalyaİlceler);
antalyaİlcelerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(antalyaİlcelerAdapter);
spinner2.setVisibility(View.VISIBLE);
editText.setVisibility(View.VISIBLE);
} else if (itemId == 2) {
burdurİlceler = new ArrayList<String>();
burdurİlceler.add("İlçe Seçiniz..");
burdurİlceler.add("Bucak");
burdurİlceler.add("Tefenni");
burdurİlceler.add("Gölhisar");
burdurİlceler.add("Ağlasun");
ArrayAdapter<String> burdurİlcelerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, burdurİlceler);
burdurİlcelerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(burdurİlcelerAdapter);
spinner2.setVisibility(View.VISIBLE);
editText.setVisibility(View.VISIBLE);
}
I am creating spinners dynamically when i click add button.but i dont know how to get the values from created dynamic spinners.I need to get values how many shirt selected, saree selected and jeans selected when i click a submit button
this is my code
buttonAdd = (Button)findViewById(R.id.add);
container = (LinearLayout)findViewById(R.id.container);
final List<String> dressArray = new ArrayList<String>();
dressArray.add("Select Dress");
dressArray.add("Shirt");
dressArray.add("Saree");
dressArray.add("Jeans");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, dressArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner dress = (Spinner) findViewById(R.id.dress);
dress.setAdapter(adapter);
final List<String> dresscountArray = new ArrayList<String>();
dresscountArray.add("Count");
dresscountArray.add("1");
dresscountArray.add("2");
dresscountArray.add("3");
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, dresscountArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner dresscount = (Spinner) findViewById(R.id.dresscount);
dresscount.setAdapter(adapter1);
buttonAdd.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
LayoutInflater layoutInflater =
(LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View addView = layoutInflater.inflate(R.layout.row, null);
Spinner dresscount = (Spinner)addView.findViewById(R.id.dresscount);
Spinner dress = (Spinner)addView.findViewById(R.id.dress);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
PickupOrder.this, android.R.layout.simple_spinner_item, dressArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dress.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
PickupOrder.this, android.R.layout.simple_spinner_item, dresscountArray);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dresscount.setAdapter(adapter1);
Button buttonRemove = (Button)addView.findViewById(R.id.remove);
buttonRemove.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
((LinearLayout)addView.getParent()).removeView(addView);
}});
container.addView(addView);
}});
Firstly define globally
String value1;
int value_position1;
And then call these methods inside onCreate after setting value in each Spinner
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
value_position1 = position;
value1 = parent.getSelectedItem().toString()
.trim();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
And when you call your submit button, use values of each String.
showallPrompt = "";
int Count = new_container.getChildCount();
try {
for (int cc = 0; cc < Count; cc++) {
View child = new_container.getChildAt(cc);
Spinner value = (Spinner)(child.findViewById(R.id.sp_dynamic));
String spin_value = value.getSelectedItem().toString();
showallPrompt += spin_value;
}
} catch (Exception e) {
}
Toast.makeText(MainActivity.this,
showallPrompt,
Toast.LENGTH_LONG).show();
}
}
Do like this on your button click...
how to disable a spinner based on another spinner. For sample, when I choose first spinner value is "Yes" then the second spinner is enable also when I choose first spinner value is "No" then the second spinner is disable.
Thanks
Try this:
final Spinner sp1 = (Spinner) findViewById(R.id.spinner1);
final Spinner sp2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<String> data = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, first);
ArrayAdapter<String> data2 = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, second);
sp1.setAdapter(data);
sp2.setAdapter(data2);
sp1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
String text = sp1.getSelectedItem().toString();
if (text.equals("No")) {
sp2.setEnabled(false);
} else {
sp2.setEnabled(true);
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
I used two spinners, country and state which i get from web-service.
i get Country in first web-service then i should pass selected country from spinner to the second web-service, How can i call the dependent Spinner in Web-service ?
Give me the example,
Thanks.
First Spinner
int i = 0;
String[] stringArray = new String[List.length];
for (i = 0; i < List.length; i++) {
stringArray[i] = Arrays.asList(List[i].Country);
}
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, stringArray);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
I had the same query some days back I guess this will solve your problem.
Add this after your spinner1 code
// here onitemselected call your second method
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
statewebservice((String) parent.getItemAtPosition(pos));
}
And for state spinner in your second web service
int i = 0;
String[] stringArray2 = new String[List2.length];
for (i = 0; i < personList1.length; i++) {
stringArray2[i] = Arrays.asList(List2[i].State);
}
Spinner spinner2 = (Spinner) findViewById(R.id.spinner2);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, stringArray2);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter2);
spinner2.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(final AdapterView<?> parent,
View view, final int pos1, long id) {
//************Code after selecting second spinner ***********
}
});
}
I've created three Spinners with certain list of values. I store each Spinner's selection value in a variable. The problem is when I go to the next page I lose my variables. What should I do?
public class TabOneActivity extends Activity implements OnItemSelectedListener{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabone);
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.fudtaste);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add(" Chineese");
categories.add(" Fast Food");
categories.add(" Traditional");
categories.add(" Mixed");
categories.add(" Favourites");
categories.add(" Combo Items");
//Toast.makeText(getApplicationContext(),newPos1,Toast.LENGTH_LONG).show();
// System.out.println(str + "sarath" );
Spinner spinner2 = (Spinner) findViewById(R.id.foodmoney);
// Spinner click listener
spinner2.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories2 = new ArrayList<String>();
categories2.add(" Fast Food");
categories2.add(" Pub Food");
categories2.add(" High End Food");
// categories2.add(" ");
// categories2.add(" Music With Food");
// categories2.add(" Enjoy The Food");
int newPos2 = spinner2.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos2,Toast.LENGTH_LONG).show();
System.out.println(newPos2 + "sarath" );
Spinner spinner3 = (Spinner) findViewById(R.id.transport);
// Spinner click listener
spinner3.setOnItemSelectedListener(this);
// Spinner Drop down elements
List<String> categories3 = new ArrayList<String>();
categories3.add(" I'll Walk");
categories3.add(" A Cab Please");
categories3.add(" Limo!!");
int newPos3 = spinner3.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos3,Toast.LENGTH_LONG).show();
System.out.println(newPos3 + "sarath" );
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories2);
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories3);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
spinner2.setAdapter(dataAdapter2);
spinner3.setAdapter(dataAdapter3);
Button bt1 = (Button)findViewById(R.id.search1);
bt1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent j = new Intent(getApplicationContext(), PlanMyDayListActivity.class);
j.putExtra("tab", 1);
startActivity(j);
}
});
}
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// // On selecting a spinner item
// String item = parent.getItemAtPosition(position).toString();
//
//// Context mContext = null;
//// Toast.makeText(mContext,item,Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(),item,Toast.LENGTH_LONG).show();
//
// }
public void onNothingSelected(AdapterView<?> arg0) {
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
}
}
try new
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
TextView tv = (TextView)arg1;
String str=tv.getText().toString();
}
this is the complete solution of your query. If you think any doubt in this, then please let me know.
import android.widget.Toast;
public class TabOneActivity extends Activity implements OnItemSelectedListener{
List<String> categories,categories2,categories3;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabone);
// Spinner element
Spinner spinner = (Spinner) findViewById(R.id.fudtaste);
// Spinner click listener
spinner.setOnItemSelectedListener(this);
// Spinner Drop down elements
categories = new ArrayList<String>();
categories.add(" Chineese");
categories.add(" Fast Food");
categories.add(" Traditional");
categories.add(" Mixed");
categories.add(" Favourites");
categories.add(" Combo Items");
//Toast.makeText(getApplicationContext(),newPos1,Toast.LENGTH_LONG).show();
// System.out.println(str + "sarath" );
Spinner spinner2 = (Spinner) findViewById(R.id.foodmoney);
// Spinner click listener
spinner2.setOnItemSelectedListener(this);
// Spinner Drop down elements
categories2 = new ArrayList<String>();
categories2.add(" Fast Food");
categories2.add(" Pub Food");
categories2.add(" High End Food");
// categories2.add(" ");
// categories2.add(" Music With Food");
// categories2.add(" Enjoy The Food");
int newPos2 = spinner2.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos2,Toast.LENGTH_LONG).show();
System.out.println(newPos2 + "sarath" );
Spinner spinner3 = (Spinner) findViewById(R.id.transport);
// Spinner click listener
spinner3.setOnItemSelectedListener(this);
// Spinner Drop down elements
categories3 = new ArrayList<String>();
categories3.add(" I'll Walk");
categories3.add(" A Cab Please");
categories3.add(" Limo!!");
int newPos3 = spinner3.getSelectedItemPosition();
//Toast.makeText(getApplicationContext(),newPos3,Toast.LENGTH_LONG).show();
System.out.println(newPos3 + "sarath" );
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories);
ArrayAdapter<String> dataAdapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories2);
ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, categories3);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
spinner2.setAdapter(dataAdapter2);
spinner3.setAdapter(dataAdapter3);
Button bt1 = (Button)findViewById(R.id.search1);
bt1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent j = new Intent(getApplicationContext(), PlanMyDayListActivity.class);
j.putExtra("tab", 1);
startActivity(j);
}
});
}
// public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// // On selecting a spinner item
// String item = parent.getItemAtPosition(position).toString();
//
//// Context mContext = null;
//// Toast.makeText(mContext,item,Toast.LENGTH_SHORT).show();
// Toast.makeText(getApplicationContext(),item,Toast.LENGTH_LONG).show();
//
// }
public void onNothingSelected(AdapterView<?> arg0) {
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
switch(arg1.getId()){
case R.id.fudtaste:
{
Toast.makeText(getApplicationContext(),"spinner clicked value: "+categories.get(arg2),Toast.LENGTH_LONG).show();
break;
}
case R.id.foodmoney:
{
Toast.makeText(getApplicationContext(),"spinner2 clicked value: "+categories2.get(arg2),Toast.LENGTH_LONG).show();
break;
}
case R.id.transport:
{
Toast.makeText(getApplicationContext(),"spinner3 clicked value: "+categories3.get(arg2),Toast.LENGTH_LONG).show();
break;
}
}
}
}
Sorry dude for this late answer!
Use shared preference