Sunday, 15 August 2010

java - Removal of override, not able to view fragment b -


I am going through this "Beginning Android Development" book. I go to the pieces section and I follow the code as show, but my compiler gives me an error MainActivity.java package com.example.fragmentsdemo;

  import android.app.activity; Importroid.os.Bundle; Import android.view.LayoutInflater; Import android.view.View; Import android.view.ViewGroup; Public class MainActivity activity {@Override public view onCreateView (LayoutInflater inflater, ViewGroup container, bundle saveInstanceState) {views = extends inflater.inflate (R.layout.my_frag, null, false); Return view; }}  

The error starts with "public view" and states "method ... main type of main activity. Java has to override or implement a super type method

To complete two XML files, below ...

  activity_main.xml & lt; RelativeLayout xmlns: Android = "http://schemas.android.com/ apk / res / android "xmlns: device =" http://schemas.android.com/tools "Android: layout_width =" match_parent "Android: layout_height =" match_parent "equipment manual =" MainActivity. "& gt; & lt ; Piece Android: id = "@ + id / fragment1 "Android: name =" ComkexamplekfragmentsdemokMyFragment "Android: Layout_width =" Wrap_content "Android: Layout_height =" Wrap_content "Android: layout_alignParentTop =" true "Android: layout_centerHorizontal =" true @ "Equipment: layout =" layout / My_frag "/> & lt; / relativeLayout & gt; my_frag.xml & lt; xml version =? 1.0 "encoding =" utf-8 "& gt; & lt; LinearLayout xmlns: android =" http://schemas.android.com/ Apk / res / android "android: layout_widt H =" match_parent "Android: layout_height =" match_parent "android: orientation =" vertical "& gt; & LT; TextView android: id =" @ + id / textView1 "Android: Layout_width =" Wrap_content "Android: Layout_height =" Wrap_content "android: text ="! Hello world with piece "Android: Text Appointment ="? Android: ATR / text Ahaparens Large "/ & gt; & Lt; / LinearLayout & gt;  

Now, when I'll have to override @'ll get, but I" Hello World Slice "does not appear! Are you present there? Any suggestions?

method OnCreateView accepts the following parameters in its original class:

  • see , string , context , AttributeSet
  • str , reference , AttributeSet

It looks like you have your activity_main.xml , Need to extend activity

instead of slice piece block, piece name your piece < / Code> must be the name of the class.


No comments:

Post a Comment