main.java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.belajar.button;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txtChange = (TextView)findViewById(R.id.txtChange);
Button btnRed = (Button)findViewById(R.id.btnRed);
Button btnBlue = (Button)findViewById(R.id.btnBlue);
btnRed.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#AA0000"));
txtChange.setText("I am red");
}
});
btnBlue.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#0000AA"));
txtChange.setText("I am blue");
}
});
}
}
package org.iimed.www;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class Penicillins extends Activity implements OnClickListener{
ImageButton back,addmed;
Context abbuttonplain;
public void onCreate(Bundle SavedInstanceState){
super.onCreate(SavedInstanceState);
setContentView(R.layout.penicillin);
back = (ImageButton) findViewById(R.id.back);
addmed = (ImageButton) findViewById(R.id.addmed);
back.setOnClickListener(this);
addmed.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.back:
startActivity(new Intent(
Penicillins.this, ImageTextListViewActivity.class));
break;
case R.id.addmed:
RelativeLayout ll=(RelativeLayout)findViewById(R.layout.sundayopen);
LayoutParams param = new
RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton adab = (ImageButton)findViewById(R.id.abbutton);
ll.addView(adab,param);
}
}
}
import android.R.color;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Application2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton Btn_living_room1 = (ImageButton) findViewById(R.id.Btn_living_room1);
Btn_living_room1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room1);
Toast toast = Toast.makeText(getApplicationContext(), "Living Room 1 Selected", Toast.LENGTH_SHORT);
toast.show();
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
}
});
final ImageButton Btn_living_room2 = (ImageButton) findViewById(R.id.Btn_living_room2);
Btn_living_room2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room2);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.two);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 2 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_living_room3 = (ImageButton) findViewById(R.id.Btn_living_room3);
Btn_living_room3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room3);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.three);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 3 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_living_room4 = (ImageButton) findViewById(R.id.Btn_living_room4);
Btn_living_room4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room4);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.four);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 4 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_exit2 = (ImageButton) findViewById(R.id.Btn_exit2);
Btn_exit2.setBackgroundColor(color.transparent);
Btn_exit2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
finish();
}
});
}
}
Read more: http://mrbool.com/how-to-use-image-buttons-and-toast-in-android/27680#ixzz2ka9aTMB0
package com.lister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button One Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button Two Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button Three Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn4 = (ImageButton)findViewById(R.id.imageButton4);
ImageButton btn5 = (ImageButton)findViewById(R.id.imageButton5);
}
}
package com.lister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
btn1.setOnClickListener(this);
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(this);
ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn3.setOnClickListener(this);
ImageButton btn4 = (ImageButton)findViewById(R.id.imageButton4);
btn4.setOnClickListener(this);
ImageButton btn5 = (ImageButton)findViewById(R.id.imageButton5);
btn5.setOnClickListener(this);
}
public void onClick(View v) {
Toast pieceToast=null;
switch (v.getId()) {
case R.id.imageButton1:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button One Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton2:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Two Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton3:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Three Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton4:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Four Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
default:
break;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.belajar.button;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView txtChange = (TextView)findViewById(R.id.txtChange);
Button btnRed = (Button)findViewById(R.id.btnRed);
Button btnBlue = (Button)findViewById(R.id.btnBlue);
btnRed.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#AA0000"));
txtChange.setText("I am red");
}
});
btnBlue.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
txtChange.setTextColor(Color.parseColor("#0000AA"));
txtChange.setText("I am blue");
}
});
}
}
package org.iimed.www;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
public class Penicillins extends Activity implements OnClickListener{
ImageButton back,addmed;
Context abbuttonplain;
public void onCreate(Bundle SavedInstanceState){
super.onCreate(SavedInstanceState);
setContentView(R.layout.penicillin);
back = (ImageButton) findViewById(R.id.back);
addmed = (ImageButton) findViewById(R.id.addmed);
back.setOnClickListener(this);
addmed.setOnClickListener(this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.back:
startActivity(new Intent(
Penicillins.this, ImageTextListViewActivity.class));
break;
case R.id.addmed:
RelativeLayout ll=(RelativeLayout)findViewById(R.layout.sundayopen);
LayoutParams param = new
RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton adab = (ImageButton)findViewById(R.id.abbutton);
ll.addView(adab,param);
}
}
}
import android.R.color;
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class Application2Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageButton Btn_living_room1 = (ImageButton) findViewById(R.id.Btn_living_room1);
Btn_living_room1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room1);
Toast toast = Toast.makeText(getApplicationContext(), "Living Room 1 Selected", Toast.LENGTH_SHORT);
toast.show();
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
}
});
final ImageButton Btn_living_room2 = (ImageButton) findViewById(R.id.Btn_living_room2);
Btn_living_room2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room2);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.two);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 2 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_living_room3 = (ImageButton) findViewById(R.id.Btn_living_room3);
Btn_living_room3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room3);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.three);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 3 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_living_room4 = (ImageButton) findViewById(R.id.Btn_living_room4);
Btn_living_room4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
v = findViewById(R.id.laidout);
v.setBackgroundResource(R.drawable.living_room4);
//get your custom_toast.xml layout
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,
(ViewGroup) findViewById(R.id.custom_toast_layout_id));
// set a dummy image
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.four);
// set a message
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Living Room 4 Selected");
// Toast...
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
});
final ImageButton Btn_exit2 = (ImageButton) findViewById(R.id.Btn_exit2);
Btn_exit2.setBackgroundColor(color.transparent);
Btn_exit2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
finish();
}
});
}
}
Read more: http://mrbool.com/how-to-use-image-buttons-and-toast-in-android/27680#ixzz2ka9aTMB0
package com.lister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
btn1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button One Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button Two Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast pieceToast= Toast.makeText(getApplicationContext(), "Image Button Three Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
}
});
ImageButton btn4 = (ImageButton)findViewById(R.id.imageButton4);
ImageButton btn5 = (ImageButton)findViewById(R.id.imageButton5);
}
}
package com.lister;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageButton btn1 = (ImageButton)findViewById(R.id.imageButton1);
btn1.setOnClickListener(this);
ImageButton btn2 = (ImageButton)findViewById(R.id.imageButton2);
btn2.setOnClickListener(this);
ImageButton btn3 = (ImageButton)findViewById(R.id.imageButton3);
btn3.setOnClickListener(this);
ImageButton btn4 = (ImageButton)findViewById(R.id.imageButton4);
btn4.setOnClickListener(this);
ImageButton btn5 = (ImageButton)findViewById(R.id.imageButton5);
btn5.setOnClickListener(this);
}
public void onClick(View v) {
Toast pieceToast=null;
switch (v.getId()) {
case R.id.imageButton1:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button One Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton2:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Two Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton3:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Three Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
case R.id.imageButton4:
pieceToast= Toast.makeText(getApplicationContext(), "Image Button Four Clicked", Toast.LENGTH_SHORT);
pieceToast.show();
break;
default:
break;
}
}
}
Posting Komentar untuk "Button Android "