You are on page 1of 2

ViewGroup -> are invisible view containers that define how the child views are laid

out, such as in a grid or a vertical list

Layout sind subclasses von ViewGroup

Each child of a LinearLayout appears on the screen in the order in which it appears
in the XML

wrap_content -> passt sich an die Lnge des Inhalts an, content = Inhalt

onClick-methoden -> mssen public und void sein, Paramter muss vom Type View sein

Intent intent = new Intent(Context, Class)


als context kann this angegeben werden weil Activity eine subclass von Context ist
2. Parameter ist eine Class (z.B eine neue Activity)

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);
}
Info: putExtra(Key, value)

public final static String EXTRA_MESSAGE = "com.mycompany.myfirstapp.MESSAGE";

->For the next activity to query the extra data, you should define the key for your
intent's extra using a public constant. It's generally a good practice to define
keys for intent extras using your app's package name as a prefix. This ensures the
keys are unique, in case your app interacts with other apps.

fertiger code:
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);
startActivity(intent);
}

You can get the Intent that started your activity by calling getIntent() and
retrieve the data contained within the intent.
->Intent intent = getIntent();

Extract the message delivered by MyActivity with the getStringExtra() method


->String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE);

Then add the TextView as the root view of the activitys layout by passing it to
setContentView().
setContentView(textView);

// Get a string resource from your app's Resources


String hello = getResources().getString(R.string.hello_world);

// Or supply a string resource to a method that requires a string


TextView textView = new TextView(this);
textView.setText(R.string.hello_world);
zustzliche Threads in onDestroy killen

Bundle -> key-value prinzip

FragmentManager -> remove,add and replace Fragments dynamicly -> FragmentTransition


--> Fragment whrend onCreate() zu Activity hinzufgen (wenn dynamisch)
An important rule when dealing with fragmentsespecially when adding fragments at
runtimeis that your activity layout must include a container View in which you can
insert the fragment.
The following layout is an alternative to the layout shown in the previous lesson
that shows only one fragment at a time. In order to replace one fragment with
another, the activity's layout includes an empty FrameLayout that acts as the
fragment container.
Inside your activity, call getSupportFragmentManager() to get a FragmentManager
using the Support Library APIs. Then call beginTransaction() to create a
FragmentTransaction and call add() to add a fragment.

You can perform multiple fragment transaction for the activity using the same
FragmentTransaction. When you're ready to make the changes, you must call commit().

You might also like