嗨,我想将视图寻呼机添加到现有代码中。什么是最好的添加方式。这是我的 RssTabActivitty.java 和 RssChannelActivity.java。
RssTabActivity 是我初始化选项卡的主要活动。RssChannelActivity 正在加载 rss 提要。
这是完整的源代码 https://github.com/itcuties/Android-Multicategory-RSS-Reader
public class RssTabsActivity extends TabActivity {
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // First, set the content view setContentView(R.layout.activity_rss_tabs); // Then get the TabHost TabHost tabHost = getTabHost(); /* ***************** * Art tab */ Intent artIntent = new Intent().setClass(this, RssChannelActivity.class); // Set Art category RSS URL artIntent.putExtra("rss-url", "http://feeds.reuters.com/news/artsculture?format=xml"); // The name of the art tab taken from the String resources 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); /* ***************** * Tech tab */ Intent techIntent = new Intent().setClass(this, RssChannelActivity.class); // Set Tech category RSS URL techIntent.putExtra("rss-url", "http://feeds.reuters.com/reuters/technologyNews?format=xml"); // Tech tab name taken from the string resources String techTabName = getResources().getString(R.string.tab_tech); TabSpec techTabSpec = tabHost.newTabSpec(techTabName) .setIndicator(techTabName, getResources().getDrawable(R.drawable.rss_tab_tech)) .setContent(techIntent); // Add tech tab to the TabHost tabHost.addTab(techTabSpec); /* ***************** * Sports tab */ Intent sportsIntent = new Intent().setClass(this, RssChannelActivity.class); // Set Sports category RSS URL sportsIntent.putExtra("rss-url", "http://feeds.reuters.com/reuters/sportsNews?format=xml"); // Sports tab name - string resources String sportsTabName = getResources().getString(R.string.tab_sports); TabSpec sportsTabSpec = tabHost.newTabSpec(sportsTabName) .setIndicator(sportsTabName, getResources().getDrawable(R.drawable.rss_tab_sports)) .setContent(sportsIntent); // Add sports tab to the TabHost tabHost.addTab(sportsTabSpec); // Set current tab to Technology tabHost.setCurrentTab(1); }
}
public class RssChannelActivity extends Activity {
// A reference to this activity private RssChannelActivity local; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rss_channel); // Get the RSS URL that was set in the RssTabActivity String rssUrl = (String)getIntent().getExtras().get("rss-url"); // Set reference to this activity local = this; GetRSSDataTask task = new GetRSSDataTask(); // Start process RSS task task.execute(rssUrl); } /** * This class downloads and parses RSS Channel feed. * * @author itcuties * */ private class GetRSSDataTask extends AsyncTask<String, Void, List<RssItem> > { @Override protected List<RssItem> doInBackground(String... urls) { try { // Create RSS reader RssReader rssReader = new RssReader(urls[0]); // Parse RSS, get items return rssReader.getItems(); } catch (Exception e) { Log.e("RssChannelActivity", e.getMessage()); } return null; } @Override protected void onPostExecute(List<RssItem> result) { // Get a ListView from the RSS Channel view ListView itcItems = (ListView) findViewById(R.id.rssChannelListView); // Create a list adapter ArrayAdapter<RssItem> adapter = new ArrayAdapter<RssItem>(local,android.R.layout.simple_list_item_1, result); // Set list adapter for the ListView itcItems.setAdapter(adapter); // Set list view item click listener itcItems.setOnItemClickListener(new ListListener(result, local)); } }
}