Top Banner
Simple User Interface
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Slide 1

Simple User InterfaceLayout

LayoutLinear layout adalah layout yang terstrukturandroid:orientation="horizontal" android:orientation="vertical"Relative layout adalah layout yang tergantungContoh layout

Add a Text FieldMenggunakan command Contoh :

Add String ResourcesWhen you need to add text in the user interface, you should always specify each string as a resourceBy default, your Android project includes a string resource file atres/values/strings.xmlContoh Add String Resources My First App Enter a message KIrim Settings MainActivity

Add a ButtonStarting Another ActivityActivityActivity adalah komponen pada aplikasi Android yang menampilkan dan mengatur halaman aplikasi sebagai tempat interaksi antara pengguna dengan aplikasiSebuah Activity mengatur satu halaman user interface aplikasiJika sebuah aplikasi Android memiliki beberapa halaman UI yang saling berinteraksi, berarti aplikasi tersebut memiliki beberapa Activity yang saling berinteraksi.Membuat Activity Baru

Membuat Event ButtonPada file xml Di res/layout/activity.xml

Pada file javaDi src/directory/activity.javapublic void methodnya(View view) { // Do something in response to button}INTENTAnIntentis an object that provides runtime binding between separate components (such as two activities)most often theyre used to start another activityPenggunaan Intentpublic void methodnya(View view) {Intent intent = new Intent(this, baruActivity.class); }

In Eclipse, press Ctrl + Shift + O to import missing classes

IntentAn intent not only allows you to start another activity, but it can carry a bundle of data to the activity as well.ContohEditText editText = (EditText) findViewById(R.id.edit_message);String message = editText.getText().toString();intent.putExtra(EXTRA_MESSAGE, message);Tambahan pada method class baruEXTRA_MESSAGE constant

Contoh Deklarasi Constantpublic class MainActivity extends ActionBarActivity {public final static String EXTRA_MESSAGE = null}Perintah untuk mengaktifkanstartActivity(intent); baris terakhir methodReceive the IntentPada method onCreate()Intent intent = getIntent();String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);Display the Messagepublic void onCreate(Bundle savedInstanceState) { ... // Create the text view TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(message);

// Set the text view as the activity layout setContentView(textView);}