0

在我使用的时候ViewPager,它的适配器需要加载View,这些View都是通过构建的LayoutInflater.inflater

但是我不知道每个页面的代码写入哪里,我不想让所有页面的代码进入MainActivity(控制 ViewPager),我想让每个页面的代码在不同的文件或类中。

你能告诉我怎么做吗?:D

4

1 回答 1

0

我想让每个页面的代码在不同的文件或类中。

使用方法创建一个 Java 类,例如 inflateViews 并将您的活动上下文传递给该方法

void inflateViews(Context context) {

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.view_inflated, null);


    }

有关LayoutInflater的更多详细信息,请参见此处。

于 2013-10-16T05:15:00.120 回答