Aufgabe 7 finished
This commit is contained in:
@@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
@@ -21,13 +22,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
toast_btn.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//send toast
|
||||
Toast.makeText(MainActivity.this, "Toast", Toast.LENGTH_SHORT).show();
|
||||
//make intent
|
||||
Intent intent = new Intent(MainActivity.this,MainActivity2.class);
|
||||
startActivity(intent);
|
||||
// additional data intent
|
||||
EditText editText = (EditText) findViewById(R.id.text_editText);
|
||||
intent.putExtra("text",editText.getText().toString());
|
||||
//sent intent
|
||||
startActivityForResult(intent,100);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if(data != null){
|
||||
String text = data.getExtras().getString("text");
|
||||
EditText editText = findViewById(R.id.text_editText);
|
||||
editText.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void call911(View view){
|
||||
Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:911"));
|
||||
startActivity(intent);
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package tech.loedige.myapplication;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.view.ActionMode;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class MainActivity2 extends AppCompatActivity {
|
||||
@@ -13,6 +17,13 @@ public class MainActivity2 extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main2);
|
||||
|
||||
Bundle extras= getIntent().getExtras();
|
||||
if(extras!= null) {
|
||||
String text = extras.getString("text");
|
||||
TextView textView = (TextView) findViewById(R.id.tv_textView);
|
||||
textView.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void makeToast(View view){
|
||||
@@ -20,4 +31,17 @@ public class MainActivity2 extends AppCompatActivity {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish(){
|
||||
Intent dataIntent = new Intent();
|
||||
EditText editText = (EditText) findViewById(R.id.text_editText);
|
||||
dataIntent.putExtra("text",editText.getText().toString());
|
||||
setResult(RESULT_OK,dataIntent);
|
||||
super.finish();
|
||||
}
|
||||
|
||||
public void sendResult(View view){
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,13 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/text_editText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/toast_btn"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/toast_btn"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -32,6 +39,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="call 911"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:onClick="call911"/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
@@ -10,7 +10,32 @@
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/text_editText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/toast_btn"
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/finish_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toRightOf="@id/text_editText"
|
||||
android:layout_alignBottom="@id/text_editText"
|
||||
android:text="Finish"
|
||||
android:onClick="sendResult"/>
|
||||
|
||||
|
||||
|
||||
<Button
|
||||
android:id="@+id/toast_btn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
|
||||
Reference in New Issue
Block a user