Aufgabe 7 finished

This commit is contained in:
Paul 2020-10-21 16:43:10 +02:00
parent fbfedab3aa
commit 2a718faa9d
7 changed files with 126 additions and 4 deletions

1
.idea/gradle.xml generated
View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Uebung7und10"> android:theme="@style/Theme.Uebung7und10">
<activity android:name=".ResultActivity"></activity>
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -1,9 +1,14 @@
package com.ploedige.uebung7und10; package com.ploedige.uebung7und10;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@Override @Override
@ -11,4 +16,22 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
} }
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
Log.v("MainActivity","requestCode:" + requestCode + "ResultCode" + resultCode);
TextView result = (TextView) findViewById(R.id.result_tv);
EditText editText = (EditText) findViewById(R.id.message_etxt);
result.setText("Result: " + data.getExtras().getString("text"));
editText.setText("Result: " + data.getExtras().getString("text"));
}
public void submit(View view){
Intent intent = new Intent(this, ResultActivity.class);
EditText editText = (EditText) findViewById(R.id.message_etxt);
intent.putExtra("text",editText.getText().toString());
startActivityForResult(intent,100);
}
} }

View File

@ -0,0 +1,36 @@
package com.ploedige.uebung7und10;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class ResultActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
Bundle extras = getIntent().getExtras();
if(extras != null){
EditText editText = (EditText) findViewById(R.id.message_etxt);
editText.setText(extras.getString("text"));
}
}
@Override
public void finish(){
Intent dataIntent = new Intent();
EditText editText = (EditText) findViewById(R.id.message_etxt);
dataIntent.putExtra("text",editText.getText().toString());
setResult(RESULT_OK,dataIntent);
super.finish();
}
public void sendResult(View view){
finish();
}
}

View File

@ -6,13 +6,36 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<TextView <EditText
android:id="@+id/message_etxt"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Hello World!" android:minWidth="30mm"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<Button
android:id="@+id/submit_btn"
android:text="Submit"
android:onClick="submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/message_etxt"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
<TextView
android:id="@+id/result_tv"
android:textSize="5mm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintBottom_toTopOf="@id/message_etxt"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ResultActivity"
android:background="@color/teal_200">
<EditText
android:id="@+id/message_etxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="30mm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"/>
<Button
android:id="@+id/sendResult_btn"
android:text="Send Result"
android:onClick="sendResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/message_etxt"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>