Actionbar Sherlock Tabs With Spinner And .setonitemselectedlistener(this)
I would like to use the tab navigation on actionbarsherlock and I have a spinner in one of the tab layouts. My Problem is: the .setOnItemSelectedListener() for the spinner is never
Solution 1:
solution found!
the definition of the view items should go to the onTabSelected method:
sp = (Spinner) findViewById(R.id.sp);
tvtest = (TextView) findViewById(R.id.tvTest);
ArrayAdapter<String> aa = newArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources()
.getStringArray(R.array.Types));
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(aa);
sp.setOnItemSelectedListener(newmySpinnerListener());
should go here:
@OverridepublicvoidonTabSelected(Tab tab, FragmentTransaction transaction) {
if (tab.getText().equals("Data Entry")) {
setContentView(R.layout.tab_dataentry);
sp = (Spinner) findViewById(R.id.sp);
tvtest = (TextView) findViewById(R.id.tvTest);
ArrayAdapter<String> aa = newArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, getResources()
.getStringArray(R.array.Types));
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(aa);
sp.setOnItemSelectedListener(newmySpinnerListener());
}
if (tab.getText().equals("Calculation")) {
setContentView(R.layout.tab_calc);
btTest = (Button) findViewById(R.id.btCalc);
btTest.setOnClickListener(this);
}
if (tab.getText().equals("Results")) {
setContentView(R.layout.tab_result);
}
}
Post a Comment for "Actionbar Sherlock Tabs With Spinner And .setonitemselectedlistener(this)"