android studio不会给我的xml充气

时间:2016-03-16 16:38:02

标签: android android-layout android-studio methods layout-inflater

我在Android工作室有一个问题,当加载模拟器时它不会将我的xml膨胀到我的java文件中它也让我在我的一种方法中遇到问题,说虽然已经导入了支持v4,但它是必需的

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;


public class ViewPagerAdapter extends FragmentPagerAdapter {

final int PAGE_COUNT = 2;
// Tab Titles
private String tabtitles[] = new String[] {"Home","Shouters"};
Context context;

public ViewPagerAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public int getCount() {
    return PAGE_COUNT;
}


    public Fragment getItem(int position) {
    switch (position) {

        // Open Fragment home.java
        case 0:
            FragmentHome fragmenthome = new FragmentHome();
            return fragmenthome;

        // Open Fragment shouters.java
        case 1:
            FragmentShouters fragmentshouter = new FragmentShouters();
            return fragmentshouter;


    }
    return null;
}

@Override
public CharSequence getPageTitle(int position) {
    return tabtitles[position];
}
}

v4问题是我获取片段主页的地方

public class FragmentHome extends Activity {


public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Get the view from fragment home.xml
    View view = inflater.inflate(R.layout.fragmenthome, container, false);
    return view;

这个问题是我的通货膨胀不会发生在我身上的?

1 个答案:

答案 0 :(得分:0)

FragmentHome应该扩展Fragment,而不是Activity