- Kód: Vybrat vše
@SuppressWarnings("deprecation")
// @SuppressWarnings annotation is here since we are using TabActivity which is deprecated in Android 4+
// Alternative way of constructing Tab Layout is to use ActionBar API
public class RssTabsActivity extends TabActivity {
Spinner sp;
String zdrojNovin;
TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
zdrojNovin = "http://www.novinky.cz/rss2/vase-zpravy?format=xml";
// First, set the content view
setContentView(R.layout.activity_rss_tabs);
sp = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> ar = ArrayAdapter.createFromResource(this, R.array.zdroje, android.R.layout.simple_spinner_item);
ar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp.setAdapter(ar);
sp.setOnItemSelectedListener(new volbaZdroje());
text = (TextView)findViewById(R.id.textView2);
TabHost tabHost = getTabHost();
Intent artIntent = new Intent().setClass(this, RssChannelActivity.class);
artIntent.putExtra("rss-url", zdrojNovin);
String artTabName = getResources().getString(R.string.tab_art);
TabSpec artTabSpec = tabHost.newTabSpec(artTabName)
.setIndicator(artTabName, getResources().getDrawable(R.drawable.rss_tab_art))
.setContent(artIntent);
// Add art tab to the TabHost
tabHost.addTab(artTabSpec);
// Set current tab to Technology
tabHost.setCurrentTab(1);
}
public class volbaZdroje implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View arg1, int pos,
long id) {
// TODO Auto-generated method stub
String zdrojN = parent.getItemAtPosition(pos).toString();
text.setText(zdrojN);
Toast.makeText(getApplicationContext(), "Načítám " + zdrojN, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
}
prosím o radu jak aktualizovat artIntent po výběru jiné položky ve spinneru, děkuji