Hallo Leute,
ich mache android tutorial Schritt für Schritt und habe folgende Problem was im Anhang steht. Wo soll ich diese Sagen implementieren?
Meine weitere Frage wäre, dass als ich DisplayMessageActivity erstellt habe war PlaceholderFragment klasse nicht inkludiert.
Letzte onCreate Methode was auf der Tutorial steht soll ich in MainActivity erweitern?
Meine Klassen schauen so aus
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.CONTAINER, new PlaceholderFragment()).commit();
}
}
@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_display_message,
container, false);
return rootView;
}
}
}
private static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
public void sendMessage(View view){
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
// Set the text view as the activity layout
setContentView(textView);
}
@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);
}
}
auf Eure Hilfe wurde ich mich sehr freuen
*** Edit ***
ich habe nach erste Fehler geschaut und habe ich Lösung gefunden in dem ich in der activity_display_message.xml android:id = "@+id/CONTAINER"
hinzugefügt habe, aber bei gleiche add Methode habe ich folgende Fehlermeldung
The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, DisplayMessageActivity.PlaceholderFragment)
weitere untere Fehler habe ich immer noch