我想创建一个包含viewPager作为标题的listView ..但是每次运行我的应用程序时崩溃都会显示当我尝试将适配器设置为寻呼机时发生错误,尽管当我取消listview时它会单独工作事情..反正在那里制作一个viewpager和listview吗?!
public class MainActivity extends SherlockActivity {
AppManager appManager;
ListView listView;
ViewPager pager;
NewsPagerAdapter pAdapter;
private int img[] = {
R.drawable.logo1new, R.drawable.image_list_loading };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//getting the app manager instance
appManager = AppManager.getInstance();
listView = (ListView)findViewById(R.id.list);
pager = (ViewPager) findViewById(R.id.pager);
pAdapter = new NewsPagerAdapter(this, img);
new DownloadNews().execute("http://mobrss.youm7.com/rss/service.svc/SelectForSpecifiedSection/SecID/12/page/1");
}
private class DownloadNews extends AsyncTask<String, Void, List<News>>{
@Override
protected List<News> doInBackground(String... params) {
// TODO Auto-generated method stub
try{
return loadXml(params[0]);
}catch(IOException e){
Log.d("IO exceptions", "ture" );
return null;
}catch(XmlPullParserException xm){
Log.d("XML exceptions", "true" );
return null;
}
}
@Override
protected void onPostExecute(List<News> result) {
Log.d("result SIZE", "" + result.size());
NewsListAdapter adapter = new NewsListAdapter(getBaseContext(), result);
listView.addHeaderView(pager);
listView.setAdapter(adapter);
pager.setAdapter(pAdapter);
}
}
private List<News> loadXml(String url) throws XmlPullParserException, IOException {
InputStream stream = null;
NewsParser newsParser = new NewsParser();
try{
stream = Utils.downloadUrl(url);
appManager.setNews(newsParser.parse(stream));
Utils.listNews(appManager.getNews());
Log.d("Appmanager", "the news set apperantly");
}finally{
if(stream != null){
stream.close();
}
}
Log.d("list items","" + appManager.getNews().size());
return appManager.getListNews() ;
}