Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 7

1.

Andoroid Manifest (replace dari <application hingga </application>) :


<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MyActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>

<activity android:name=".Activity2"></activity>
<activity android:name=".Activity3"></activity>

</application>

2. String Resources (replace dari tag <resources> hingga </resources> :


<resources>

<string name="app_name">PraktikumApp</string>
<string name="hello_world">Hello world!</string>
<string name="action_settings">Settings</string>

</resources>
3. MyActivity.java :
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MyActivity extends Activity implements View.OnClickListener {

Button buttonShow,buttonNext;
EditText eText;
TextView textOutput;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);

buttonShow = (Button) findViewById(R.id.button);


buttonNext = (Button) findViewById(R.id.button2);
eText = (EditText) findViewById(R.id.editText);
textOutput= (TextView) findViewById(R.id.textView3);
buttonShow.setOnClickListener(this);
buttonNext.setOnClickListener(this);
}

public void onClick(View v) {


Intent i = new Intent(MyActivity.this, Activity2.class);
switch(v.getId()) {
case R.id.button:
String input = eText.getText().toString();
textOutput.setText(textOutput.getText()+" "+input);
break;
case R.id.button2:
startActivity(i);
break;
}

}
4. Activity2.java :
import android.app.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;

/**
* Created by SONY on 11/14/2014.
*/
public class Activity2 extends Activity implements View.OnClickListener{

RadioButton radioChosen;
CheckBox checkConfirm;
Button buttonNext;
RadioGroup radioGroup;

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

checkConfirm = (CheckBox) findViewById(R.id.checkBox4);


buttonNext = (Button) findViewById(R.id.button);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup2);
checkConfirm.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
buttonNext.setEnabled(true);
}
});

buttonNext.setOnClickListener(this);
}

public void onClick (View v){


Intent i = new Intent(Activity2.this, Activity3.class);

int selectedId = radioGroup.getCheckedRadioButtonId();

radioChosen = (RadioButton) findViewById(selectedId);

i.putExtra("radioChosen",radioChosen.getText());

startActivity(i);
}

5. Activity3.java :
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
* Created by SONY on 11/14/2014.
*/
public class Activity3 extends Activity implements View.OnClickListener{

TextView info;
String tAnswer;
Button bBrowser;

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

info = (TextView) findViewById(R.id.textView);


bBrowser = (Button) findViewById(R.id.button);

Intent intent = getIntent();


tAnswer = intent.getStringExtra("radioChosen");

if (tAnswer.equals("Pohang Steelers")){
info.setText("Jawaban kamu : "+tAnswer+"\n"+"Jawaban kamu benar! Pilih tombol dibawah
untuk mengetahui info lebih lanjut tentang Pohang Steelers");
//Jawaban kamu benar! Pilih tombol dibawah untuk mengetahui info lebih lanjut tentang Pohang
Steelers
} else {
info.setText("Jawaban kamu : "+tAnswer+"\n"+"Jawaban kamu kurang tepat! Pilih tombol
dibawah untuk mengetahui info lebih lanjut tentang Pohang Steelers");
//Jawaban kamu kurang tepat! Pilih tombol dibawah untuk mengetahui info lebih lanjut tentang
Pohang Steelers
}
bBrowser.setOnClickListener(this);
}

public void onClick(View arg0) {


Intent browserIntent =
new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.co.id/search?
q=pohang+steelers"));
startActivity(browserIntent);
}

You might also like