I have a ViewPager , for which I use a ViewPagerAdapter extends PagerAdapter .
The adapter creates an Item for the ViewPager'a method:

  @Override public Object instantiateItem(ViewGroup container,final int position) {} 

It is necessary:

  1. Fill the ViewPager old data.
  2. Run an animation of horizontal progressBar on the current item.
  3. Update ViewPager.

Question: How to access the View ( ProgressBar'у ) of the current item to animate. In what methods can all this be done?

For example:

  1. Old data is 30 percent. Older data is displayed first.
  2. Then it loads up to 54 percent.
  3. As a result, we see a page with 54 percent. On other elements ( Item'ах ), the data must also be updated as a result. We just don’t see it and no animation is needed on other elements.

All this happens at the Activity onCreate event. Data on item'aх should not be updated for other events.

 public class MyViewPagerAdapter extends PagerAdapter { private Activity mActivity; private int mPageCount; private List<SummaryResult.Summary> summaryInfoList; int currentStatus; int currentPeriodNum; public MyViewPagerAdapter(Activity activity,int pageCount, List<SummaryResult.Summary> summaryInfoList,int currentStatus,int currentPeriodNum) { mActivity = activity; mPageCount = pageCount; this.summaryInfoList = summaryInfoList; this.currentStatus = currentStatus; this.currentPeriodNum = currentPeriodNum; } View mCurrentView; @Override public void setPrimaryItem(ViewGroup container, int position, Object object) { super.setPrimaryItem(container, position, object); mCurrentView = (View)object; String text = ((TextView)mCurrentView.findViewById(R.id.periodTitleTextView)).getText().toString(); if (text != null){ Log.w("Log_page",text); } Log.w("Log_page","position = " + position); } @Override public int getCount() { return mPageCount; } @Override public boolean isViewFromObject(View view, Object obj) { return (view ==(View)obj); } @Override public Object instantiateItem(ViewGroup container,final int position) { ViewGroup viewGroup = (ViewGroup)mActivity.getLayoutInflater().inflate( R.layout.item_card_summary, null); SummaryResult.Summary result = summaryInfoList.get(position); String[] numbers = {"","Первый","Второй","Третий","Четвёртый","Пятый","Шестой","Седьмой","Восьмой","Девятый","Десятый","Одинадцатый","Двенадцатый"}; TextView periodTitleTextView = (TextView)viewGroup.findViewById(R.id.periodTitleTextView); TextView periodDurationTextView = (TextView)viewGroup.findViewById(R.id.periodDurationTextView); final TextView progressTextView = (TextView)viewGroup.findViewById(R.id.progressTextView); TextView factTextView = (TextView)viewGroup.findViewById(R.id.factTextView); TextView planTextView = (TextView)viewGroup.findViewById(R.id.planTextView); LinearLayout errorBar = (LinearLayout)viewGroup.findViewById(R.id.errorBar); TextView noMetrAccessTextView = (TextView)viewGroup.findViewById(R.id.noMetrAccessTextView); TextView companyStopTextView = (TextView)viewGroup.findViewById(R.id.companyStopTextView); TextView factTitleTextView = (TextView)viewGroup.findViewById(R.id.factTitleTextView); LinearLayout factLinearLayout = (LinearLayout)viewGroup.findViewById(R.id.factLinearLayout); ImageView statusImageView = (ImageView)viewGroup.findViewById(R.id.statusImageView); TextView planVisitsTextView = (TextView)viewGroup.findViewById(R.id.planVisitsTextView); TextView factVisitsTextView = (TextView)viewGroup.findViewById(R.id.factVisitsTextView); container.addView(viewGroup); return viewGroup; } @Override public void destroyItem(ViewGroup collection, int position, Object view) { //must be overridden else throws exception as not overridden. collection.removeView((View) view); } @Override public float getPageWidth(int position) { return 0.89f; } enum CurentStatus{ CompanyNorm(0), CompanyStop(1), CompanyError(2); private final int value; private CurentStatus(int value){ this.value = value; } public int getIntValue(){ return value; } } 

}

  • Add ViewPagerAdapter code to question - anber
  • i.e. to make public methods for fragments and to pull them is not an option at all? - aratj

1 answer 1

You can try to set the tag with setTag() for the progressBar, and then find this view with findViewWithTag(mytag)