当我点击btnMeat时,只显示黑页。我想显示片段页面。我真的很困惑。
我的主页:
public class Main extends Activity {
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.main);
Button btnMeat=(Button)findViewById(R.id.meat);
btnMeat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
Intent intent=new Intent(Main.this,MeatList.class);
startActivity(intent);
}
catch (Exception ex){
Toast.makeText(getApplicationContext(),ex.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
meatList:
public class MeatList extends FragmentActivity {
public void OnCreate(Bundle bundle){
super.onCreate(bundle);
setContentView(R.layout.Meatlist);
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpagerMeat);
viewPager.setAdapter(new MyAdapter(getSupportFragmentManager()));
}
public class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return new MeatList1();
case 1:
return new MeatList2();
default:
return null;
}
}
@Override
public int getCount() {
return 2;
}
}
}
meatList1:
public class MeatList1 extends Fragment {
public void OnCreate(Bundle bundle){
super.onCreate(bundle); }
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
RelativeLayout relativeLayout = (RelativeLayout) inflater.inflate(R.layout.meatlist1,container,false);
return relativeLayout;
}
catch (Exception e){
Toast.makeText(getActivity().getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
return null;
}
meatList.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/viewpagerMeat"
/>
</LinearLayout>
的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.easyshopping">
<uses-sdk android:minSdkVersion="10"/>
<application android:label="@string/app_name" >
<activity android:name=".SplashActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".Main">
</activity>
<activity android:name=".MeatList"></activity>
<activity android:name=".BreadList"></activity>
<activity android:name=".DiaryList"></activity>
<activity android:name=".FruitList"></activity>
</application>
</manifest>
logcat的:
2-04 17:59:07.866: DEBUG/AndroidRuntime(735): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-04 17:59:07.866: DEBUG/AndroidRuntime(735): CheckJNI is ON
12-04 17:59:08.833: DEBUG/AndroidRuntime(735): Calling main entry com.android.commands.pm.Pm
12-04 17:59:09.063: DEBUG/dalvikvm(374): GC_EXPLICIT freed 4K, 54% free 2538K/5511K, external 1625K/2137K, paused 77ms
12-04 17:59:09.063: WARN/ActivityManager(68): No content provider found for:
12-04 17:59:09.593: WARN/ActivityManager(68): No content provider found for:
12-04 17:59:09.622: DEBUG/PackageParser(68): Scanning package: /data/app/vmdl1973873727.tmp
12-04 17:59:10.272: INFO/PackageManager(68): Removing non-system package:com.example.easyshopping
12-04 17:59:10.272: INFO/ActivityManager(68): Force stopping package com.example.easyshopping uid=10034
12-04 17:59:10.323: INFO/Process(68): Sending signal. PID: 723 SIG: 9
12-04 17:59:10.342: INFO/ActivityManager(68): Force finishing activity HistoryRecord{40541a40 com.example.easyshopping/.Main}
12-04 17:59:10.392: ERROR/InputDispatcher(68): channel '40776c80 com.example.easyshopping/com.example.easyshopping.Main (server)' ~ Consumer closed input channel or an error occurred. events=0x8
12-04 17:59:10.392: ERROR/InputDispatcher(68): channel '40776c80 com.example.easyshopping/com.example.easyshopping.Main (server)' ~ Channel is unrecoverably broken and will be disposed!
12-04 17:59:10.402: INFO/WindowManager(68): WIN DEATH: Window{407377e0 com.example.easyshopping/com.example.easyshopping.MeatList paused=false}
12-04 17:59:10.432: INFO/WindowManager(68): WIN DEATH: Window{40776c80 com.example.easyshopping/com.example.easyshopping.Main paused=true}
12-04 17:59:10.452: ERROR/InputDispatcher(68): Received spurious receive callback for unknown input channel. fd=150, events=0x8
12-04 17:59:10.492: WARN/InputManagerService(68): Got RemoteException sending setActive(false) notification to pid 723 uid 10034
12-04 17:59:11.272: DEBUG/dalvikvm(68): GC_CONCURRENT freed 1107K, 59% free 4338K/10375K, external 3125K/3903K, paused 28ms+11ms
12-04 17:59:11.312: DEBUG/PackageManager(68): Scanning package com.example.easyshopping
12-04 17:59:11.312: INFO/PackageManager(68): Package com.example.easyshopping codePath changed from /data/app/com.example.easyshopping-2.apk to /data/app/com.example.easyshopping-1.apk; Retaining data and using new
12-04 17:59:11.312: INFO/PackageManager(68): Unpacking native libraries for /data/app/com.example.easyshopping-1.apk
12-04 17:59:11.375: DEBUG/installd(35): DexInv: --- BEGIN '/data/app/com.example.easyshopping-1.apk' ---
12-04 17:59:13.452: DEBUG/dalvikvm(744): DexOpt: load 224ms, verify+opt 1034ms
12-04 17:59:13.705: DEBUG/installd(35): DexInv: --- END '/data/app/com.example.easyshopping-1.apk' (success) ---
12-04 17:59:13.705: WARN/PackageManager(68): Code path for pkg : com.example.easyshopping changing from /data/app/com.example.easyshopping-2.apk to /data/app/com.example.easyshopping-1.apk
12-04 17:59:13.705: WARN/PackageManager(68): Resource path for pkg : com.example.easyshopping changing from /data/app/com.example.easyshopping-2.apk to /data/app/com.example.easyshopping-1.apk
12-04 17:59:13.705: DEBUG/PackageManager(68): Activities: com.example.easyshopping.SplashActivity com.example.easyshopping.Main com.example.easyshopping.MeatList com.example.easyshopping.BreadList com.example.easyshopping.DiaryList com.example.easyshopping.FruitList
12-04 17:59:13.723: INFO/ActivityManager(68): Force stopping package com.example.easyshopping uid=10034
12-04 17:59:13.924: INFO/installd(35): move /data/dalvik-cache/data@app@com.example.easyshopping-1.apk@classes.dex -> /data/dalvik-cache/data@app@com.example.easyshopping-1.apk@classes.dex
12-04 17:59:13.933: DEBUG/PackageManager(68): New package installed in /data/app/com.example.easyshopping-1.apk
12-04 17:59:14.243: INFO/ActivityManager(68): Force stopping package com.example.easyshopping uid=10034
12-04 17:59:14.343: DEBUG/dalvikvm(212): GC_EXPLICIT freed 3K, 50% free 2868K/5703K, external 6487K/7982K, paused 89ms
12-04 17:59:14.585: WARN/RecognitionManagerService(68): no available voice recognition services found
12-04 17:59:14.833: DEBUG/dalvikvm(228): GC_EXPLICIT freed 84K, 53% free 2762K/5767K, external 1625K/2137K, paused 459ms
12-04 17:59:14.943: DEBUG/dalvikvm(68): GC_EXPLICIT freed 482K, 60% free 4231K/10375K, external 3125K/3903K, paused 143ms
12-04 17:59:14.993: INFO/installd(35): unlink /data/dalvik-cache/data@app@com.example.easyshopping-2.apk@classes.dex
12-04 17:59:15.003: DEBUG/AndroidRuntime(735): Shutting down VM
12-04 17:59:15.033: DEBUG/dalvikvm(735): GC_CONCURRENT freed 101K, 72% free 295K/1024K, external 0K/0K, paused 1ms+1ms
12-04 17:59:15.033: DEBUG/jdwp(735): Got wake-up signal, bailing out of select
12-04 17:59:15.033: DEBUG/dalvikvm(735): Debugger has detached; object registry had 1 entries
12-04 17:59:15.075: INFO/dalvikvm(735): JNI: AttachCurrentThread (from ???.???)
12-04 17:59:15.075: INFO/AndroidRuntime(735): NOTE: attach of thread 'Binder Thread #3' failed
12-04 17:59:15.665: DEBUG/AndroidRuntime(747): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
12-04 17:59:15.665: DEBUG/AndroidRuntime(747): CheckJNI is ON
12-04 17:59:16.713: DEBUG/AndroidRuntime(747): Calling main entry com.android.commands.am.Am
12-04 17:59:16.763: INFO/ActivityManager(68): Starting: Intent { flg=0x10000000 cmp=com.example.easyshopping/.SplashActivity } from pid 747
12-04 17:59:16.975: DEBUG/AndroidRuntime(747): Shutting down VM
12-04 17:59:17.003: DEBUG/dalvikvm(747): GC_CONCURRENT freed 102K, 69% free 319K/1024K, external 0K/0K, paused 2ms+1ms
12-04 17:59:17.043: INFO/ActivityManager(68): Start proc com.example.easyshopping for activity com.example.easyshopping/.SplashActivity: pid=756 uid=10034 gids={}
12-04 17:59:17.053: DEBUG/jdwp(747): Got wake-up signal, bailing out of select
12-04 17:59:17.053: DEBUG/dalvikvm(747): Debugger has detached; object registry had 1 entries
12-04 17:59:17.103: INFO/AndroidRuntime(747): NOTE: attach of thread 'Binder Thread #3' failed
12-04 17:59:18.433: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 52K, 53% free 2556K/5379K, external 1950K/2137K, paused 75ms
12-04 17:59:18.873: INFO/ActivityManager(68): Displayed com.example.easyshopping/.SplashActivity: +1s907ms
12-04 17:59:22.543: INFO/ActivityManager(68): Starting: Intent { cmp=com.example.easyshopping/.Main } from pid 756
12-04 17:59:22.723: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 7K, 53% free 2576K/5379K, external 2371K/2503K, paused 70ms
12-04 17:59:22.883: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 1K, 53% free 2577K/5379K, external 3033K/3495K, paused 62ms
12-04 17:59:23.173: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 1K, 52% free 2584K/5379K, external 4072K/4156K, paused 74ms
12-04 17:59:23.434: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 1K, 52% free 2587K/5379K, external 5568K/5622K, paused 61ms
12-04 17:59:23.733: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 1K, 52% free 2590K/5379K, external 6951K/7452K, paused 70ms
12-04 17:59:24.013: DEBUG/dalvikvm(756): GC_EXTERNAL_ALLOC freed 1K, 52% free 2593K/5379K, external 8311K/9048K, paused 64ms
12-04 17:59:24.573: INFO/ActivityManager(68): Displayed com.example.easyshopping/.Main: +1s999ms
12-04 17:59:29.816: DEBUG/dalvikvm(212): GC_EXPLICIT freed 8K, 50% free 2870K/5703K, external 6516K/7982K, paused 166ms
12-04 17:59:30.873: INFO/ActivityManager(68): Starting: Intent { cmp=com.example.easyshopping/.MeatList } from pid 756
12-04 17:59:31.303: INFO/ActivityManager(68): Displayed com.example.easyshopping/.MeatList: +400ms
12-04 17:59:35.323: DEBUG/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
12-04 17:59:41.164: DEBUG/dalvikvm(374): GC_EXPLICIT freed 6K, 54% free 2538K/5511K, external 1625K/2137K, paused 114ms
12-04 17:59:46.293: DEBUG/dalvikvm(387): GC_EXPLICIT freed 2K, 55% free 2531K/5511K, external 1625K/2137K, paused 145ms
12-04 17:59:51.273: DEBUG/dalvikvm(275): GC_EXPLICIT freed 8K, 55% free 2591K/5703K, external 1625K/2137K, paused 93ms
MeatList1.XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2e2d2d">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
>
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:id="@+id/logo"
android:background="@drawable/logo1"
android:layout_marginTop="10dp"
android:layout_alignParentLeft="true"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/cart"
android:background="@drawable/cart"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/home"
android:background="@drawable/home"
android:layout_marginTop="10dp"
android:layout_toLeftOf="@id/cart"
android:layout_marginRight="65dp"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="@+id/line"
android:background="@drawable/line"
android:layout_marginTop="55dp"
/>
</RelativeLayout>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="20dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal"
android:id="@+id/linearfirstRow1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/meat1"
android:background="@drawable/meat1"
>
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/meat1title"
android:text="Hardwood Smoked Bacon "
android:textColor="#2aff0c"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/meat1" android:layout_marginTop="20dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/meat1more"
android:text="more"
android:layout_below="@id/meat1title" android:textStyle="bold" android:textColor="#2aff0c"
android:layout_alignRight="@+id/meat1title" android:layout_marginTop="20dp">
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:id="@+id/meatfirsarrow"
android:layout_below="@+id/linearfirstRow1" android:gravity="center|center_horizontal">
<ImageView
android:layout_width="15dp"
android:layout_height="20dp"
android:background="@drawable/nextpageleft"
android:layout_marginTop="20dp" android:layout_alignParentLeft="true"
android:layout_alignParentRight="false">
</ImageView>
<ImageView
android:layout_width="15dp"
android:layout_height="20dp"
android:background="@drawable/nextpageright"
android:layout_marginTop="20dp" android:layout_alignParentRight="true">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal"
android:id="@+id/linearSecondRow1"
android:layout_below="@id/meatfirsarrow"
android:layout_marginTop="20dp"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="@+id/meat2"
android:background="@drawable/meat2"
>
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/meat2title"
android:text="Recipe Breakfast Sausage"
android:textColor="#2aff0c"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@id/meat2" android:layout_marginTop="20dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/meat2more"
android:text="more"
android:layout_below="@id/meat2title" android:textStyle="bold" android:textColor="#2aff0c"
android:layout_alignRight="@+id/meat2title" android:layout_marginTop="20dp">
</TextView>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="50dp"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="1dp"
android:id="@+id/linefooter"
android:background="@drawable/line"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/info"
android:background="@drawable/info"
android:layout_marginRight="10dp"
android:layout_marginTop="2dp"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/email"
android:background="@drawable/email"
android:layout_toLeftOf="@+id/info"
android:layout_alignParentRight="true"
android:layout_marginRight="65dp"
android:layout_marginTop="2dp"
/>
</RelativeLayout>
</LinearL
ayout&GT;
答案 0 :(得分:0)
我写过OnCreate()而不是onCreate(); public void OnCreate(Bundle bundle){ super.onCreate(束);