Suffer brain for a long time, please gurus help me, I am a novice! I can not find the definition of good control findViewById I do not know why. Specific original code as follows:
Under the original layout xml file code:
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
android: layout_centerHorizontal = "true"
android: layout_centerVertical = "true"
tools: context = ". Activity01" />
android: id = "@ + id / mybutton"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: layout_alignParentBottom = "true"
android: layout_alignParentLeft = "true"
tools: context = ". Activity01" />
R file ID of the original code:
public static final class id {
public static final int menu_settings = 0x7f070002;
public static final int mybutton = 0x7f070001;
public static final int mytext = 0x7f070000;
}
java files under src file original code:
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_activity01);
TextView myText = (TextView) this.findViewById (android.R.id.mytext);
Button mybutton = (Button) this.findViewById (android.R.id.mybutton);
}
As shown above, mytext and mybutton tips mytext cannot be resolved or is not a field. Please help prawn.
Reply:
android.R.id.mytext to R.id.mytext
android.R.id.mybutton to R.id.mybutton
Reply:
The Android removed! Upstairs like that!
Reply:
If there is not, we project - clean look, to reconstruct the environment.
Reply:
TextView myText = (TextView) this.findViewById (android.R.id.mytext);
The problem
Reply:
TextView myText = (TextView) this.findViewById (android.R.id.mytext);
Button mybutton = (Button) this.findViewById (android.R.id.mybutton);
R package your guide wrong. To guide your project corresponding R package
Reply:
Ah upstairs said all right. Your package into wrong.
TextView myText = (TextView) this.findViewById (android.R.id.mytext);
Should be replaced
TextView myText = (TextView) this.findViewById (R.id.mytext);
Delete the imported above you. Then re-import.
Reply:
Agree upstairs
Reply:
The R's import and then deleted according to the first floor said
Reply:
1st Floor positive solution http://dalvik.co.cc
Reply:
You can try adding the red code TextView myText = (TextView) this myText findViewById (android.R.id.mytext);..
Button mybutton = (Button) this . Mybutton . FindViewById (android.R.id. mybutton);
Reply:
Do you have first option to save layout.
No comments:
Post a Comment