如何在ViewPager的Layouts中传播ListViews?

时间:2013-01-12 17:07:26

标签: android android-listview android-viewpager

在我的Android应用程序中,我有一个ViewPager,里面有2个视图,navigation_activity和另一个变量布局。当应用程序启动时,它将从home_activity(这是开始的变量布局)开始,但是如果向左滑动到导航栏并单击按钮,我需要变量布局从主页切换到另一个视图...现在我有这样一个系统:

public class ViewPagerAdapter extends PagerAdapter
{
static int iFocusedActivity = R.layout.activity_home;

public int getCount()
{
    return 2;
}

public Object instantiateItem(View collection, int position) 
{            
    LayoutInflater inflater = (LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    int resId = 0;
    switch (position) 
    {
    case 0:
        resId = R.layout.activity_navigation;
        break;
    case 1:
        resId = iFocusedActivity;
        break;
    }
    View view = inflater.inflate(resId, null);
    ((ViewPager) collection).addView(view, 0);
    return view;
}

public boolean isViewFromObject(View arg0, Object arg1)
{
    return arg0 == ((View) arg1);
}

public static void setFocus(int iActivity)
{
    iFocusedActivity = iActivity;
}

public void destroyItem( View pager, int position, Object view )
{
    ((ViewPager)pager).removeView( (View)view );
}

}

它改变了视图很好,(调用了setFocus()并为分页器添加了新的adpater)问题是我有一个名为layout_verblist的布局,其中ListView需要在布局被采用时传播寻呼机,但只是在按钮点击上调用代码没有做任何事情......这被证明是一个巨大的问题。如何在Viewpager中传播布局列表?

0 个答案:

没有答案