activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/tvSalam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/etNama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/tvSalam"
android:layout_below="@+id/etNama"
android:layout_marginTop="16dp"
android:layout_toLeftOf="@+id/bSapa"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/bSapa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/editText1"
android:onClick="bSapaClick"
android:layout_marginRight="25dp"
android:text="Sapa" />
</RelativeLayout>
Graphical Layout
Main Activity.java
package com.helloword;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
public void
bSapaClick(View v){
EditText etNama = (EditText)
findViewById(R.id.etNama);
TextView tvSalam = (TextView)
findViewById(R.id.tvSalam);
String nama = etNama.getText().toString();
tvSalam.setText("Hallo
"+nama+" senang bertemu dengan anda!");
}
}
Layout running
Tidak ada komentar:
Posting Komentar