I have two fragments, a HomeFragment and a SettingsFragment. In the Settingsfragment I have a spinner. Depending on what item is selected in the spinner, i want to either set the maximum of progress bar higher or lower. So I have a string variable (spinnerTime) in settingsfragment class, but I want to have access to this string variable in the home class. How can I do this? Do I have to work with an interface here? Heres the code a function in homefragment class:
public void handleProgress(){
countDownTimer = new CountDownTimer(86400*1000,1000) {
#Override
public void onTick(long millisUntilFinished) {
//EDIT: added thes lines:
SharedPreferences sp =
getContext().getSharedPreferences("spinner",
Context.MODE_PRIVATE);
String spinnerTime = sp.getString("spinner", "");
progress = progress +1;
progressBar.setProgress(progress);
if (spinnerTime.equals("1min")){
progressBar.setMax(60);
} else if (spinnerTime.equals("30min")){
progressBar.setMax(1800);
} else if (spinnerTime.equals("1h")) {
progressBar.setMax(3600);
} else if (spinnerTime.equals("24h")) {
progressBar.setMax(3600*24);
}
}
The following code shows the settingsfragment class:
public class SettingsFragment extends Fragment {
Spinner spinner;
ImageView ring_spinner;
String item;
String spinnerTime;
TextView tv_timeOfCircle;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.settingsfragment, container);
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
ring_spinner = (ImageView) view.findViewById(R.id.ring_spinner);
tv_timeOfCircle = view.findViewById(R.id.textView);
spinner = (Spinner) view.findViewById(R.id.spinner);
handleSpinner();
super.onViewCreated(view, savedInstanceState);
}
public void handleSpinner(){
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.numbers, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
item = parent.getItemAtPosition(position).toString();
spinnerTime = spinner.getSelectedItem().toString();
//EDIT: added the four following lines to the
//settingsfragment class
sp = getActivity().getSharedPreferences("spinner",
getContext().MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("spinnerStr", spinnerTime);
editor.commit();
Toast showItem = Toast.makeText(parent.getContext(),
spinnerTime, Toast.LENGTH_SHORT);
showItem.show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
Now of course i have got a cannot resolve symbol "spinnerTime" error. Has somebody an idea to solve this? Id be really grateful for any advice
Related
I am not an expert in android studio with java and I would like to know how to obtain the value declared within the setOnItemSelectedListener method (variable option_name). I have declared a spinner which shows a series of options, what I want is to extract the option to use it in the onCreateView for later insert it in a database together with other texts that are obtained from editText. Greetings
my code:
public class genera_debate extends Fragment {
EditText date,time_hour;
TextView test;
Spinner list_of_interest;
Button PostDiscussion;
public String name_perfil,alias_perfil,option_interest,option_name;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_genera_debate,container,false);
test =view.findViewById(R.id.test);
PostDiscussion= view.findViewById(R.id.button4);
list_of_interest =view.findViewById(R.id.subject_of_interest);
String [] subject = {"Tema de interés","Política","Deporte","Animales","Videojuegos","Economía","Medicina","Cultura","Ciencia","Tecnología","Música","Otros"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_spinner_item, subject);
list_of_interest.setAdapter(adapter);
list_name.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
option_name = (String ) parent.getItemAtPosition(position);
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
return view;
}
I have a Activity that contains a NavigationDrawer, and this NavDrawer starts a fragment if i enter in some item. So, into one of this itens, i have a fragment that contains a TabHost with 4 Fragments in Swipe effect with PageViewer(PacksFragment).
The problem stay in the first fragment of TabHost, the TabFragmentA. While i was doing the interface, It would open and function normally. But when I started programming, everytime i was going to test, or the application would not open, or the application stops working when i enter in the fragment parent of TabFragmentA
The sequence of Activity and fragments is this:
MainActivity > PacksFragment > TabFragmentA, TabFragmentB, TabFragmentC, TabFragmentD
PacksFragment.java
public class PacksFragment extends Fragment
implements ViewPager.OnPageChangeListener, TabHost.OnTabChangeListener {
TabHost tabHost;
ViewPager viewPager;
public PacksFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_packs, container, false);
final TabHost host = (TabHost) view.findViewById(R.id.tabhost);
host.setup();
viewPager = (ViewPager) view.findViewById(R.id.viewPager);
List<Fragment> listFragments = new ArrayList<Fragment>();
listFragments.add(new TabFragmentA());
listFragments.add(new TabFragmentB());
listFragments.add(new TabFragmentC());
listFragments.add(new TabFragmentD());
MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(
getFragmentManager(), listFragments);
viewPager.setAdapter(myFragmentPagerAdapter);
viewPager.setOnPageChangeListener(this);
tabHost = (TabHost) view.findViewById(R.id.tabhost);
tabHost.setup();
String[] tabNames = {"NUIA", "HARANYA", "OCEANIC", "AURORIA"};
for(int i=0; i<tabNames.length; i++) {
TabHost.TabSpec tabSpec;
tabSpec = tabHost.newTabSpec(tabNames[i]);
tabSpec.setIndicator(tabNames[i]);
tabSpec.setContent(new FakeContent(getActivity().getApplicationContext()));
tabHost.addTab(tabSpec);
View tabView = host.getTabWidget().getChildTabViewAt(i);
tabView.setPadding(0, 0, 0, 0);
TextView tv = (TextView)tabView.findViewById(android.R.id.title);
tv.setSingleLine();
tv.setTextSize(13);
tv.setTextColor(0xFFFFFFFF);
}
tabHost.setOnTabChangedListener(this);
return view;
}
public class FakeContent implements TabHost.TabContentFactory {
Context context;
public FakeContent(Context mcontext) {
context = mcontext;
}
#Override
public View createTabContent(String tag) {
View fakeView = new View(context);
fakeView.setMinimumHeight(0);
fakeView.setMinimumWidth(0);
return fakeView;
}
}
#Override
public void onTabChanged(String tabId) {
int selectedItem = tabHost.getCurrentTab();
viewPager.setCurrentItem(selectedItem);
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageSelected(int selectedItem) {
tabHost.setCurrentTab(selectedItem);
}
}
TabFragmentA.java
public class TabFragmentA extends Fragment {
Spinner spinnerLocalCrafting;
private static final String[]locates = {"Solzreed Peninsula", "Gweonid Forest", "Lilyut Hills", "Dewstone Planes", "White Arden",
"Marianople", "Two Crowns", "Cinderstone Moore", "Halcyona", "Hellswamp", "Sanddeep", "Airain Rock", "Aubre Cradle",
"Ahnimar", "Karkasse Ridgelands"};
private List<RadioButton> tipoPackRadioButtons;
private static final int[] IDS_TIPOPACK_RADIO = { R.id.tipoPackRadio1, R.id.tipoPackRadio2, R.id.tipoPackRadio3,
R.id.tipoPackRadio4, R.id.tipoPackRadio5, R.id.tipoPackRadio6};
public TabFragmentA() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_layout_a, container, false);
//Spinner
spinnerLocalCrafting = (Spinner) v.findViewById(R.id.spinnerLocalCrafting);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, locates);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerLocalCrafting.setAdapter(adapter);
spinnerLocalCrafting.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//TabFragmentA tabFragmentA = new TabFragmentA();
//tabFragmentA.setSpinnerSelected(position);
//methodCalculate();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Log.d("FUCK", String.valueOf(getActivity()));
// Not return NULL
//RadioButtons
tipoPackRadioButtons = new ArrayList<RadioButton>();
for(int id : IDS_TIPOPACK_RADIO) {
RadioButton tipoPackRadioBt = (RadioButton) v.findViewById(id);
tipoPackRadioButtons.add(tipoPackRadioBt);
}
//RadioGroup
RadioGroup radioGroupTipoPack = new RadioGroup(getActivity());
int count2 = 0;
while(count2 < 6) {
radioGroupTipoPack.addView(tipoPackRadioButtons.get(count2));
count2++;
}
return v;
}
public static TabFragmentA newInstance(String text) {
TabFragmentA f = new TabFragmentA();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
/*public static int spinnerSelected;
public static void setSpinnerSelected(int spinnerSelected) {
TabFragmentA.spinnerSelected = spinnerSelected;
}*/
/*public void methodCalculate() {
int count = 0;
while(count < 16) {
switch (spinnerSelected) {
case count:
break;
}
count++;
}
}*/
}
In the log appears
You trying to add a RadioButton to your View that is already attached to another View. In this line you get RadioButtons from View:
RadioButton tipoPackRadioBt = (RadioButton) v.findViewById(id);
and then you try to add them to your View again:
radioGroupTipoPack.addView(tipoPackRadioButtons.get(count2));
1- If you already defined RadioButtons in xml you don't have to add them again, just find them via findViewById and edit them if you want -> Remove 2nd line
2- If you want to define RadioButtons dynamically during run time just leave RadioGroup empty, then Inflate or Create RadioButtons and add them to the group -> Remove 1st line.
P.S: You can Also try to Remove RadioButtons from their parent view and add them to another view but it's error prone and you should avoid doing so unless you really need to..
I'm new to Android and I'm trying to get a String from spinner. I've made some research but I couldn't find anything useful. Without trying to get String the code is working properly. This is the code which is working:
assert staticSpinner2 != null;
staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
}
public String getSpin(String spinnerLanguage2) {
return spinnerLanguage2;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
I tried to use a getter method as follows where I didn't get any errors:
assert staticSpinner2 != null;
staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
}
public String getSpinnerString(String spinnerLanguage2) {
return spinnerLanguage2;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
I'm trying to set this String to a text view using:
assert staticSpinner2 != null;
staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
}
public String getSpinnerString(String spinnerLanguage2) {
return spinnerLanguage2;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
MainActivityClassName AnObject = new MainActivityClassName();
text.setText(AnObject.getSpinnerString());
Where I get an error saying "cannot resolve method getSpin()". I do realise I'm not passing any parameters to the method but I don't know how I can do it here. I appreciate any help or any other advice to solve the problem in a different way. Thanks in advance.
This is the full code if that helps:
public class MainActivity extends AppCompatActivity {
TextView text;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_json);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
text = (TextView) findViewById(R.id.textView);
// spinner 1
final Spinner staticSpinner1 = (Spinner) findViewById(R.id.spinner1);
// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapter1 = ArrayAdapter
.createFromResource(this, R.array.lang,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
staticAdapter1
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
staticSpinner1.setAdapter(staticAdapter1);
// spinner 2
final Spinner staticSpinner2 = (Spinner) findViewById(R.id.spinner2);
staticSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String spinnerLanguage = staticSpinner1.getSelectedItem().toString();
switch (spinnerLanguage) {
case "Afrikaans":
// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapterAF = ArrayAdapter
.createFromResource(getBaseContext(), R.array.af,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
staticAdapterAF
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
staticSpinner2.setAdapter(staticAdapterAF);
break;
case "French":
// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapterFR = ArrayAdapter
.createFromResource(getBaseContext(), R.array.fr,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
staticAdapterFR
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
staticSpinner2.setAdapter(staticAdapterFR);
break;
case "English":
// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapterEN = ArrayAdapter
.createFromResource(getBaseContext(), R.array.en,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
staticAdapterEN
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
staticSpinner2.setAdapter(staticAdapterEN);
break;
case "Turkish":
// Create an ArrayAdapter using the string array and a default spinner
ArrayAdapter<CharSequence> staticAdapterTR = ArrayAdapter
.createFromResource(getBaseContext(), R.array.tr,
android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
staticAdapterTR
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
staticSpinner2.setAdapter(staticAdapterTR);
break;
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
assert staticSpinner2 != null;
staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String spinnerLanguage2 = staticSpinner2.getSelectedItem().toString();
}
public String getSpin(String spinnerLanguage2) {
return spinnerLanguage2;
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
MainActivity AnObject = new MainActivity();
text.setText(AnObject.getSpinnerString());
}
}
You can do this:
String selectedText = null;
staticSpinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
selectedText = parent.getItemAtPosition(position).toString();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
Now you can use the selectedText variable to pass on to whatever method you want. But, keep in mind, unless you select something in the spinner, it's value would be null.
If you really have to use it outer, you can do this :
public void setTextView(String text){
text.setText(text);
}
and call this method inside your onItemSelected:
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
setTextView(staticSpinner2.getSelectedItem().toString());
}
Having read that piece of code, why don't you extract "spinnerLanguage2" to your main class and then access it from there? Assigning the value inside the OnItemSelected method.
EDIT:
My previous answer is wrong. Try to implement an interface in order to communicate with the other class. Thus, calling a method of that interface you can pass the value. I give you a link with this (It explains it for fragments, but yo can communicate your classes too):
http://developer.android.com/intl/es/training/basics/fragments/communicating.html
I have a ListFragment OnItemClick is not working; it's basically not getting called. I have been unable to find any errors in my code. Is this somehow a problem with getListView?
I've explored Google and StackOverflow but did not find a solution. Here's my code:
public class FragmentSongs extends ListFragment implements OnFragmentCreatedListener,OnItemClickListener {
static ListView lv;
private static final String TAG = FragmentSongs.class.getSimpleName();
MediaMetadataRetriever metaRetriver1;
Vector<ForPLaylist> gtuMcaBean= new Vector<ForPLaylist>();
Forplaylistadapter adaptor;
String artist="";
static int i=0,f=0,k=0;;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
trial t=new trial();
t.onCreate();
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.playlist, container,false);
metaRetriver1 = new MediaMetadataRetriever();
lv=(ListView) root.findViewById(android.R.id.list);
//data calculation here
lv.setAdapter(adaptor);
// lv = getListView();//showing error here if i call it
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
int songIndex=position;
Intent in = new Intent(getActivity(), AndroidBuildingMusicPlayerActivity.class);
in.putExtra("songIndex",songIndex);
startActivityForResult(in, 100);
closefragment();
}
});
return root;
}
OnFragmentCreatedListener listener;
private void closefragment() {
getActivity().getFragmentManager().popBackStack();
}
#Override
public void onFragmentCreated(ArrayList<String> msg) {
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
int songIndex=position;
Intent in = new Intent(null, AndroidBuildingMusicPlayerActivity.class);
in.putExtra("songIndex",songIndex);
startActivityForResult( in,100);
finish();
}
private void finish() {
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.d(TAG, "onActivityCreated");
if(savedInstanceState != null) {
Log.d(TAG, "saved variable number: " + savedInstanceState.getInt("number"));
}
super.onActivityCreated(savedInstanceState);
// lv=getListView();
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// lv = getListView();
}
}
try move your getListView();to onActivityCreated and make sure you call super.onActivityCreated(savedInstanceState) first
I think you should check the code in onItemClick of ListFragment (not the code of onItemClick inside onCreateView method):
Intent in = new Intent(null, AndroidBuildingMusicPlayerActivity.class);
Just change it to:
Intent in = new Intent(getActivity(), AndroidBuildingMusicPlayerActivity.class);
I'm facing some issue with getting spinning values from list view.. in list view i have textview and related to spinner to it..
this is my Result.java
public class Result extends ListActivity{
SpinnerWrapper wrapper=new SpinnerWrapper();
Spinner sp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result);
MyAdapter adap=new MyAdapter(this, android.R.layout.simple_list_item_1,R.id.textView1, getResources().getStringArray(R.array.modules));
adap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
setListAdapter(adap);
Button b=(Button) findViewById(R.id.button12);
//final Spinner sp=(Spinner) findViewById(R.id.spinner1);
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent=new Intent(Result.this,Cal.class);
for(int i=0;i<15;i++){
//String text= sp1.getSelectedItem().toString();
//Log.d("This", text);
}
//Spinner sp1=og.getSp();
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(Result.this, R.array.grades, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(wrapper);
intent.putExtra("values", sp.getSelectedItem().toString());
//intent.putExtra("values", sp.setOnItemSelectedListener(wrapper));
startActivity(intent);
}
});
}
public void getObject(Spinner sp){
this.sp=sp;
}
private class MyAdapter extends ArrayAdapter<String>{
public MyAdapter(Context context, int resource, int textViewResourceId,
String[] strings) {
super(context, resource, textViewResourceId, strings);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.item_layout, parent,false);
String[] items=getResources().getStringArray(R.array.modules);
TextView tv=(TextView) row.findViewById(R.id.textView1);
tv.setText(items[position]);
Spinner sp=(Spinner)row.findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter=ArrayAdapter.createFromResource(Result.this, R.array.grades, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(adapter);
getObject(sp);
//og.setSp(sp);
//sp.setOnItemSelectedListener(wrapper);
//int dd=row.getId();
return row;
}
}
}
My Spinner Wrapper class is looks like this..
public class SpinnerWrapper implements OnItemSelectedListener {
public SpinnerWrapper() {
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
String text=parent.getSelectedItem().toString();
int intee=parent.getSelectedItemPosition();
String pos=Integer.toString(intee);
String tex=parent.getItemAtPosition(position).toString();
Log.d("Selected", text);
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
I want to get spinning value of each spinner ..how can i do that??
//sp.setOnItemSelectedListener(wrapper);
I see your code is commented. so the OnItemSelectedListener is not called.
You call different listener for different spinner.
I don't see why you can't get the value by
String tex=parent.getItemAtPosition(position).toString();
Log.d("You have selected", tex);
You can create an ArrayList<String> and add the selected value to that ArrayList. It will be something like this.
static ArrayList<String> sth = new ArrayList<String>();
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
Toast.makeText(
parent.getContext(),
"OnItemSelectedListener : "
+ parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
for (int i = 0; i < parent.getItemIdAtPosition(pos); i++) {
sth.add(parent.getItemAtPosition(pos).toString());
}
Log.w(getClass().getSimpleName(), "sth size " + sth.size());
}
You can pass that ArrayList around since the selected values are stored.