Skip to content

Commit 0517a26

Browse files
committed
Update the Android first example
1 parent b73d168 commit 0517a26

7 files changed

Lines changed: 27 additions & 19 deletions

File tree

-5.08 KB
Loading
-2.18 KB
Loading
-8.94 KB
Loading
-18.7 KB
Loading

com.vogella.android.first/res/layout/activity_main.xml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@
88
android:paddingTop="@dimen/activity_vertical_margin"
99
tools:context=".MainActivity" >
1010

11-
<TextView
12-
android:id="@+id/textView1"
11+
<EditText
12+
android:id="@+id/main_input"
1313
android:layout_width="wrap_content"
1414
android:layout_height="wrap_content"
15-
android:text="@string/hello_world" />
15+
android:layout_alignParentLeft="true"
16+
android:layout_alignParentTop="true"
17+
android:layout_marginLeft="14dp"
18+
android:ems="10" >
1619

17-
<!--
18-
NOTE: More attributes are required
19-
for the correct layout of the ImageView. These are feft
20-
out for brevity
21-
-->
20+
<requestFocus />
21+
</EditText>
2222

23-
<ImageView
24-
android:id="@+id/myicon"
23+
<Button
24+
android:id="@+id/button1"
2525
android:layout_width="wrap_content"
2626
android:layout_height="wrap_content"
27-
android:src="@drawable/initial" />
27+
android:layout_alignLeft="@+id/editText1"
28+
android:layout_below="@+id/editText1"
29+
android:layout_marginTop="31dp"
30+
android:onClick="onClick"
31+
android:text="Start" />
2832

2933
</RelativeLayout>

com.vogella.android.first/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33

4-
<string name="app_name">Test</string>
4+
<string name="app_name">First Android</string>
55
<string name="action_settings">Settings</string>
66
<string name="hello_world">Hello world!</string>
77

com.vogella.android.first/src/com/vogella/android/first/MainActivity.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import android.app.Activity;
44
import android.os.Bundle;
55
import android.util.Log;
6-
import android.view.Menu;
6+
import android.view.View;
7+
import android.widget.EditText;
8+
import android.widget.Toast;
79

810
public class MainActivity extends Activity {
911

@@ -16,11 +18,13 @@ protected void onCreate(Bundle savedInstanceState) {
1618
setContentView(R.layout.activity_main);
1719
}
1820

19-
@Override
20-
public boolean onCreateOptionsMenu(Menu menu) {
21-
// Inflate the menu; this adds items to the action bar if it is present.
22-
getMenuInflater().inflate(R.menu.main, menu);
23-
return true;
24-
}
21+
// you may have here an onCreateOptionsMenu method
22+
// this method is not required for this exercise
23+
// therefore I deleted it
2524

25+
public void onClick(View view) {
26+
EditText input = (EditText) findViewById(R.id.main_input);
27+
String string = input.getText().toString();
28+
Toast.makeText(this, string, Toast.LENGTH_LONG).show();
29+
}
2630
}

0 commit comments

Comments
 (0)