Monday, May 5, 2014

android. setText mistake, find a lot of answers still do not know why


android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
android: background = "# C7EDCC">

android: id = "@ + id/text1"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: text = "text1"
android: textSize = "30sp"
android: textColor = "# 8B3A3A"
android: gravity = "right"
android: layout_marginTop = "15px"
/>
android: id = "@ + id/text2"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: layout_marginTop = "10dip"
android: textColor = "# 000000"
android: textSize = "19sp"
android: text = "text2"
/>


public class MainActivity extends Activity {
private TextView myTxt;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
/ / ----------------------------
myTxt = (TextView) findViewById (R.id.text2);
myTxt.setText ("ajfijwofjowiejfoiewoi");
/ / ----------------------------
if (savedInstanceState == null) {
getFragmentManager (). beginTransaction ()
. Add (R.id.container, new PlaceholderFragment ()) commit ();.
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
myTxt is null
Reply:
That amount is how to write, where I did not write Yeah
Reply:
reference to the second floor lsTMango reply:
amount that is how to write, where I did not write Yeah

Either do not fragment, or the processing into Fragment in myTxt
Reply:
reference to the third floor hjywyj reply:
Quote: references to the second floor lsTMango reply:

That amount is how to write, where I did not write Yeah

Either do not fragment, or will myTxt processing into Fragment Lane

- How to get solve novice
Reply:
Great God soon appear online Yeah. . .
Reply:
reference to the third floor hjywyj reply:
Quote: references to the second floor lsTMango reply:

That amount is how to write, where I did not write Yeah

Either do not fragment, or will myTxt processing into Fragment Lane

On the inside or have been deleted or not try! ! ! !
Reply:
Your R.id.container in there? ? ? Code did not paste the full right?
Reply:
reference to the 7th floor lxwwd reply:
your R.id.container in there? ? ? Code did not paste the full right?

package com.example.zno4_textview2;



import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
/ / ---------------------------------
import android.graphics.Color;
import android.widget.TextView;
/ / ---------------------------------
public class MainActivity extends Activity {
private TextView myTxt;
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);

if (savedInstanceState == null) {
getFragmentManager (). beginTransaction ()
. Add (R.id.container, new PlaceholderFragment ()) commit ();.
}
/ / ----------------------------
myTxt = (TextView) findViewById (R.id.text2);
myTxt.setText ("ajfijwofjowiejfoiewoi");
/ / MyTxt.setTextColor (Color.BLUE);
/ / MyTxt.setTextSize (19);
/ / ----------------------------
}

@ Override
public boolean onCreateOptionsMenu (Menu menu) {

/ / Inflate the menu; this adds items to the action bar if it is present
.getMenuInflater () inflate (R.menu.main, menu);.
return true;
}

@ Override
public boolean onOptionsItemSelected (MenuItem item) {
/ / Handle action bar item clicks here. The action bar will
/ / Automatically handle clicks on the Home / Up button, so long
/ / As you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId ();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected (item);
}

/ **
* A placeholder fragment containing a simple view.
* /
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment () {
}

@ Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment_main, container,
false);

return rootView;
}
}

}

Reply:
reference to the 7th floor lxwwd reply:
your R.id.container in there? ? ? Code did not paste the full right?

Could it be I was under the Eclipse version too high?
Reply:
 

/ **
* A placeholder fragment containing a simple view.
* /
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment () {
}
private TextView myTxt;
@ Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment_main, container,
false);
myTxt = (TextView) rootView.findViewById (R.id.text2);
myTxt.setText ("Hello World!");
return rootView;
}
}

Reply:
reference to the 10th floor hjywyj reply:
 

/ **
* A placeholder fragment containing a simple view.
* /
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment () {
}
private TextView myTxt;
@ Override
public View onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate (R.layout.fragment_main, container,
false);
myTxt = (TextView) rootView.findViewById (R.id.text2);
myTxt.setText ("Hello World!");
return rootView;
}
}
Thank you ah finally, it seems that the next code to be written there, although now understand this PlaceholderFragment is used to do

No comments:

Post a Comment