當我在異步任務的onPostexecute方法完成後將適配器設置爲viewpager時,我得到此異常並且應用程序強制關閉。 「ViewPager尚未綁定」ViewPager尚未綁定
我正在爲TabPage指標使用jakeWhartons Viewpager指標。
有沒有修復它?
code snippet。
public class MyDetailedActivity extends FragmentActivity {
ViewPager pager;
PageIndicator mIndicator;
ProgressBar progressBar1;
ProgressBar progressBar2;
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.ac_image_pager);
progressBar1 = (ProgressBar)findViewById(R.id.progressBarPager1);
progressBar2 = (ProgressBar)findViewById(R.id.progressBarPager2);
progressBar1.setVisibility(View.VISIBLE);
progressBar2.setVisibility(View.VISIBLE);
//Declare Pagers & Indicators
//Pager-Top
pager = (ViewPager) findViewById(R.id.pager);
pager.setClipToPadding(false);
pager.setPageMargin(12);
//Indicator of Pager-Top
mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
new PastEventFullDetailDownloader(past_event_id).execute(null,null,null);
}
private class PastEventFullDetailDownloader extends AsyncTask<String,String, String>
{
protected String doInBackground(String... params) {
//Download data
}
protected void onPostExecute(String result) {
displayEvent(result);
}
}
void displayEvent(PastEventInfo event)
{
//hide the progressbars
progressBar1.setVisibility(View.GONE);
progressBar2.setVisibility(View.GONE);
//Set Up Adapter for First Pager ..Pass ImageUrsl Just Downloaded
pager.setAdapter(new ImagePagerAdapter(event.getEventImageUrsl()));
pager.setCurrentItem(pagerPosition);
mIndicator.setViewPager(pager);
}
}
stacktrace和相關的代碼會幫助 – donfuxx
@donfuxx我已經添加了代碼片段和異常堆棧跟蹤。請仔細看看 – zee
@donfuxx你有什麼想法隊友嗎? ( – zee