2
我試圖在片段中顯示一個我的頁面,但它給了我一個錯誤。通過片段顯示活動時出現錯誤
我創建了一個名爲FragmentContacts.java的單獨Class文件,從中我顯示了activity_contacts.xml的佈局。
FragmentContacts Java代碼:
package me.example.app;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class FragmentContacts extends FragmentActivity {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Get the view from fragmenttab1.xml
View view = inflater.inflate(R.layout.activity_contacts, container, false);
return view;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// setUserVisibleHint(true);
}
}
片段代碼:
public Fragment getItem(int arg0) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
//Fragment fragment = new DummySectionFragment();
//Bundle args = new Bundle();
//args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
//fragment.setArguments(args);
//return fragment;
switch (arg0) {
// Open FragmentTab1.java Error on return fragmenttab1
case 0:
FragmentContacts fragmenttab1 = new FragmentContacts();
return fragmenttab1;
return null;
}
它不給你'一個error'。它給你一些非常具體的東西。這裏沒有人是巫師。什麼是錯誤? – nhgrif
剛剛解決它。我分別創建了Fragment,現在它工作。謝謝 –
您應該刪除問題,或發佈您的解決問題的答案,然後接受該答案。 – nhgrif