Sie sind auf Seite 1von 18

1. Tuliskan script untuk mendeclare dan memberikan action!

asdada

public class MainActivity extends AppCompatActivity {


// deklarasi tombol
private Button mBtn_login, mBtn_register;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//inisial tombol
mBtn_login = (Button)findViewById(R.id.btn_login);
mBtn_register=(Button)findViewById(R.id.btn_register);

// function tombol
mBtn_login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent iLogin = new Intent(getApplicationContext(),LoginActivity.class);
startActivity(iLogin);
}
});

mBtn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent iRegister = new Intent(getApplicationContext(), RegisterActivity.class);
startActivity(iRegister);
}
});
}
}

2. Buat script Java dengan menggunakan ListView

Jawab:

package halo.example.com.customlistview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

int[] IMAGES = {R.drawable.Foto1, R.drawable.Foto2, R.drawable.Foto3};

String[] NAMES = {
"Adinda", "Almer", "Dandy” };

String[] DESCRIPTIONS = {“Gender1”, “Gender2”, “Gender3”};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ListView ListView=(ListView)findViewById(R.id.ListView);

CustomAdapter customAdapter=new CustomAdapter();

ListView.setAdapter(customAdapter);
}

class CustomAdapter extends BaseAdapter{


@Override
public int getCount() {
return IMAGES.length;
}

@Override
public Object getItem(int i) {
return null;
}

@Override
public long getItemId(int i) {
return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = getLayoutInflater().inflate(R.layout.customlayout,null);

ImageView imageView=(ImageView)view.findViewById(R.id.imageView);
TextView textView_name=(TextView)view.findViewById(R.id.textView_name);
TextView textView_descriptions=(TextView)view.findViewById(R.id.textView_descriptions);

imageView.setImageResource(IMAGES[i]);
textView_name.setText(NAMES[i]);
textView_descriptions.setText(DESCRIPTIONS[i]);

return view;
}
}
}

3.Two Activities

# Main Activities
package com.example.android.twoactivities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
* The TwoActivities app contains two activities and sends messages (intents)
* between them.
*/
public class MainActivity extends AppCompatActivity {
/* Class name for Log tag */
private static final String TAG_ACTIVITY = MainActivity.class.getSimpleName();
/* Unique tag required for the intent extra */
public static final String EXTRA_MESSAGE = "com.example.android.twoactivities.MESSAGE";
/* Unique tag for the intent reply */
public static final int TEXT_REQUEST = 1;

/* EditText view for the message */


private EditText mMessage = null;
/* TextView for the reply header */
private TextView mReplyHead = null;
/* TextView for the reply body */
private TextView mReply = null;

/**
* Initialize the activity.
* @param savedInstanceState The current state data
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/* initialize all the view variables */


mMessage = (EditText) findViewById(R.id.editText_main);
mReplyHead = (TextView) findViewById(R.id.text_header_reply);
mReply = (TextView) findViewById(R.id.text_message_reply);
}

/**
* Handle the onClick for the "Send" button. Gets the value
* of the main EditText, creates an intent, and launches the
* second activity with that intent.
*
* The return intent from the second activity is onActivityResult().
* @param view The view (Button) that was clicked.
*/
public void launchSecondActivity(View view) {
Log.d(TAG_ACTIVITY, "Button clicked!");

Intent intent = new Intent(this, SecondActivity.class);


String message = "";
if (mMessage != null) {
message = mMessage.getText().toString();
}

intent.putExtra(EXTRA_MESSAGE, message);
startActivityForResult(intent, TEXT_REQUEST);
}

/**
* Handle the data in the return intent from SecondActivity.
*
* @param requestCode Code for the SecondActivity request.
* @param resultCode Code that comes back from SecondActivity.
* @param data Intent data sent back from SecondActivity.
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == TEXT_REQUEST) {
if (resultCode == RESULT_OK) {
String reply = data.getStringExtra(SecondActivity.EXTRA_REPLY);

if (mReplyHead != null) {
mReplyHead.setVisibility(View.VISIBLE);
}

if (mReply != null) {
mReply.setText(reply);
mReply.setVisibility(View.VISIBLE);
}

}
}
}
}

#Second Activity
package com.example.android.twoactivities;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

/**
* SecondActivity defines the second activity in the app. It is launched from an intent
* with a message, and sends an intent back with a second message.
*/
public class SecondActivity extends AppCompatActivity {
/* Unique tag for the intent reply. */
public static final String EXTRA_REPLY =
"com.example.android.twoactivities.REPLY";

/* EditText for the reply */


private EditText mReply = null;

/**
* Initialize the activity.
* @param savedInstanceState The current state data
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

/* initialize view variables */


mReply = (EditText) findViewById(R.id.editText_second);

/* Get the intent that launched this activity, and the message in
the intent extra. */
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

/* Put that message into the text_message TextView */


TextView textView = (TextView) findViewById(R.id.text_message);
if (textView != null) {
textView.setText(message);
}
}

/**
* Handle the onClick for the "Reply" button. Gets the message
* from the second EditText, creates an intent, and returns
* that message back to the main activity.
*
* @param view The view (Button) that was clicked.
*/
public void returnReply(View view) {
/* Get the reply message from the edit text */
String reply = "";
if (mReply != null) {
reply = mReply.getText().toString();
}

/* Create a new intent for the reply, add the reply message to it as an extra,
set the intent result, and close the activity. */
Intent replyIntent = new Intent();
replyIntent.putExtra(EXTRA_REPLY, reply);
setResult(RESULT_OK, replyIntent);
finish();
}
}

4. Flowchart aplikasi ecommerce

Design aplikasi ecommerce:


5. a Design / mock up aplikasi Pengisian Evaluasi Dosen Oleh Mahasiswa (dengan tambahan fitur
rate/nilai aplikasi)

5 b Widget yg digunakan

Button -> sebagai tombol submit

In android, Button is a user interface control which is used to perform an action whenever the user
click or tap on it.

Generally, Buttons in android will contains a text or an icon or both and perform an action when user
touches it.

Radio Group -> sebagai wadah/tempat untuk memilih jurusan (dalam aplikasi ini ada 4 jurusan kursus
yang salah satunya diikuti si pendaftar(

In android, Radio Group is used to group one or more radio buttons into separate groups based on
our requirements.
If we group Radio Buttons using RadioGroup, at a time only one item can be selected from the
group of radio buttons. In case, if we select one radio button that belongs to a radio group will
unselect all other previously selected radio buttons within in the same group.

Initially, all the radio buttons of radio group are in unchecked state, once we select a radio button
then it’s not possible for us to uncheck it like CheckBox control.

Checkboxes -> sebagai wadah/tempat untuk memilih ketertarikan divisi pada Computer Club 2018.
Ketertarikan bisa dipilih lebih dari 1

In android, CheckBox is a two states button that can be either checked (ON) or unchecked (OFF) and
it will allow users to toggle between the two states (ON / OFF) based on the requirements.

Generally, we can use multiple CheckBox controls in android application to allow users to select one
or more options from the set of values.

Rating bar -> digunakan untuk memberi penilaian pada aplikasi tsb

In android, RatingBar is a UI control which is used to get the rating from the user. The RatingBar is
an extension of SeekBar and ProgressBar that shows a rating in stars and it allow users to set the
rating value by touch or click on the stars.

The android RatingBar will always return a rating value as floating point number such as 1.0, 2.0, 2.5,
3.0, 3.5, etc.

c. Script Java

package kel1.nico.pendaftarancc2018;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity {


private RatingBar rBar;
private TextView tView;
private Button btn;
RadioButton android, java, angular, python;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rBar = (RatingBar) findViewById(R.id.ratingBar1);
tView = (TextView) findViewById(R.id.textview1);
android = (RadioButton)findViewById(R.id.rdbAndroid);
angular = (RadioButton)findViewById(R.id.rdbAngular);
java = (RadioButton)findViewById(R.id.rdbJava);
python = (RadioButton)findViewById(R.id.rdbPython);
android = (CheckBox)findViewById(R.id.chkAndroid);
angular = (CheckBox)findViewById(R.id.chkAngular);
Button btn2 = (Button)findViewById(R.id.getD);
Button getBtn = (Button)findViewById(R.id.getBtn);
btn2.setOnClickListener(new View.OnClickListener() {
getBtn.setOnClickListener(new View.OnClickListener() {
btn = (Button)findViewById(R.id.btnGet);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int noofstars = rBar.getNumStars();
float getrating = rBar.getRating();
tView.setText("Rating: "+getrating+"/"+noofstars);
String result = "Selected Course: ";
result+= (android.isChecked())?"Android":
(angular.isChecked())?"AngularJS":(java.isChecked())?"Java":
(python.isChecked())?"Python":"";
Toast.makeText(getApplicationContext(), result,
Toast.LENGTH_SHORT).show();
}
});
}
public void onRadioButtonClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
String str="";
// Check which radio button was clicked
switch(view.getId()) {
case R.id.rdbAndroid:
if(checked)
str = "Android Selected";
break;
case R.id.rdbAngular:
if(checked)
str = "AngularJS Selected";
break;
case R.id.rdbJava:
if(checked)
str = "Java Selected";
break;
case R.id.rdbPython:
if(checked)
str = "Python Selected";
break;
}
Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_SHORT).show();
}
}

public void onCheckboxClicked(View view) {


boolean checked = ((CheckBox) view).isChecked();
String str="";
// Check which checkbox was clicked
switch(view.getId()) {
case R.id.chkAndroid:
str = checked?"Android Selected":"Android Deselected";
break;
case R.id.chkAngular:
str = checked?"AngularJS Selected":"AngularJS
Deselected";
break;

}
Toast.makeText(getApplicationContext(), str,
Toast.LENGTH_SHORT).show();
}
}
}
});
}
}

Script XML

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

<TextView

android:id="@+id/textView74"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_weight="1"

android:text="EDOM DOSEN"
android:textColor="#000000"

android:textSize="32dp"/>

<TextView

android:id="@+id/textView75"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:layout_marginTop="105dp"

android:text="Dosen1" />

<TextView

android:id="@+id/textView76"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:layout_marginTop="162dp"

android:text="dosen2" />

<TextView

android:id="@+id/textView77"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentStart="true"

android:layout_alignParentTop="true"

android:layout_marginTop="216dp"

android:text="Dosen3" />
<TextView

android:id="@+id/textView78"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentStart="true"

android:layout_marginBottom="222dp"

android:text="Dosen4" />

<TextView

android:id="@+id/textView79"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView75"

android:layout_alignStart="@+id/textView74"

android:layout_marginBottom="-105dp"

android:text="SB" />

<TextView

android:id="@+id/textView80"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView75"

android:layout_centerHorizontal="true"

android:layout_marginBottom="-105dp"

android:text="B" />

<TextView
android:id="@+id/textView81"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView75"

android:layout_marginBottom="-105dp"

android:layout_toEndOf="@+id/textView74"

android:text="K" />

<RadioButton

android:id="@+id/radioButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/textView74"

android:layout_alignTop="@+id/textView75" />

<RadioButton

android:id="@+id/radioButton3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignTop="@+id/textView75"

android:layout_centerHorizontal="true" />

<RadioButton

android:id="@+id/radioButton4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignEnd="@+id/textView81"

android:layout_alignTop="@+id/textView75" />
<RadioButton

android:id="@+id/radioButton5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/textView74"

android:layout_alignTop="@+id/textView76" />

<RadioButton

android:id="@+id/radioButton6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/textView74"

android:layout_alignTop="@+id/textView78" />

<RadioButton

android:id="@+id/radioButton7"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/textView74"

android:layout_alignTop="@+id/textView77" />

<RadioButton

android:id="@+id/radioButton8"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/radioButton4"

android:layout_alignTop="@+id/textView77" />

<RadioButton
android:id="@+id/radioButton9"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/radioButton4"

android:layout_alignTop="@+id/textView78" />

<RadioButton

android:id="@+id/radioButton10"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignStart="@+id/radioButton4"

android:layout_alignTop="@+id/textView76" />

<RadioButton

android:id="@+id/radioButton11"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignTop="@+id/textView77"

android:layout_centerHorizontal="true" />

<RadioButton

android:id="@+id/radioButton12"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignTop="@+id/textView76"

android:layout_centerHorizontal="true" />

<RadioButton

android:id="@+id/radioButton13"
android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignTop="@+id/textView78"

android:layout_centerHorizontal="true" />

<TextView

android:id="@+id/textView82"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

android:layout_alignParentStart="true"

android:layout_marginBottom="158dp"

android:text="PASTIKAN ANDA SUDAH MENGISI SEMUA" />

<CheckBox

android:id="@+id/checkBox"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBottom="@+id/textView82"

android:layout_alignStart="@+id/radioButton4"

android:text="Yes" />

</RelativeLayout>

Das könnte Ihnen auch gefallen