import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
public class Test extends Activity {
/** Called when the activity is first created. */
LinearLayout linearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearLayout= new LinearLayout(this);//线性布局
LinearLayout.LayoutParams layoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton imageButton_1 = new ImageButton(this);
imageButton_1.setLayoutParams(layoutParams);
imageButton_1.setImageDrawable(getResources().getDrawable(
R.drawable.icon));
linearLayout.addView(imageButton_1);
imageButton_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new AlertDialog.Builder(Test.this)
.setTitle("提示")
.setMessage("我是ImageButton1")
.setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
}).create();//创建按钮
dialog.show();
}
});
setContentView(linearLayout);
}
public LinearLayout getView(){
return linearLayout;
}
}
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
public class Test extends Activity {
/** Called when the activity is first created. */
LinearLayout linearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
linearLayout= new LinearLayout(this);//线性布局
LinearLayout.LayoutParams layoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton imageButton_1 = new ImageButton(this);
imageButton_1.setLayoutParams(layoutParams);
imageButton_1.setImageDrawable(getResources().getDrawable(
R.drawable.icon));
linearLayout.addView(imageButton_1);
imageButton_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new AlertDialog.Builder(Test.this)
.setTitle("提示")
.setMessage("我是ImageButton1")
.setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
}
}).create();//创建按钮
dialog.show();
}
});
setContentView(linearLayout);
}
public LinearLayout getView(){
return linearLayout;
}
}