public class Test extends Activity {
/** Called when the activity is first created. */
private Button.OnClickListener button_listener = new Button.OnClickListener() {
public void onClick(View v) {
showDialog(1);
}
};
private Button.OnClickListener listener2 = new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(2);
}
};
private Button.OnClickListener listener3 = new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(3);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init() {
// TODO Auto-generated method stub
Button button1 = (Button) findViewById(R.id.button1);
Button button2 = (Button) findViewById(R.id.button2);
Button button3 = (Button) findViewById(R.id.button3);
button1.setOnClickListener(button_listener);
button2.setOnClickListener(listener2);
button3.setOnClickListener(listener3);
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 1: {
Dialog dialog = new AlertDialog.Builder(Test.this).setTitle("Question")
.setMessage("one111111111111111111111")// 设置内容
.setPositiveButton("Yes", // 设置确定按钮
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();// 创建
return dialog;
}
case 2: {
ScrollView sv = new ScrollView(this);
TextView tv = new TextView(this);
tv.setText("2");
sv.addView(tv);
Dialog dialog2 = new AlertDialog.Builder(Test.this).setTitle("Question")
.setView(sv)// 设置内容
.setPositiveButton("Yes", // 设置确定按钮
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();// 创建
return dialog2;
}
case 3: {
ScrollView sv = new ScrollView(this);
TextView tv = new TextView(this);
tv.setText("3");
sv.addView(tv);
Dialog dialog3 = new AlertDialog.Builder(Test.this).setTitle("Question")
.setView(sv)// 设置内容
.setPositiveButton("Yes", // 设置确定按钮
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();// 创建
return dialog3;
}
default: {
return null;
}
}
}
}
原来是把配置文件的appliction写错地方了,不是新建,而是在主运行程序上。添加个android:name属性,捣腾了半天才弄好,呵呵
1、新建继承appliction的类
package com.Notepad;
import android.app.Application;
import android.graphics.Bitmap;
public class MyApp extends Application{
private Bitmap mBitmap;
public Bitmap getMBitmap() {
return mBitmap;
}
public void setMBitmap(Bitmap bitmap) {
mBitmap = bitmap;
}
}
2、AndroidMainfest.xml配置name属性
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name =".MyApp" >
3、获取和设置
MyApp app=(MyApp)getApplication();
Bitmap myBitmap=app.getMBitmap();//获取到图片对象
MyApp myApp = ((MyApp)getApplication());
myApp.setMBitmap(mBitmap);
闲来没事,给大家分享一下自己在使用listView的过程中遇到的一下情况以及解决的办法。
1 listview中在设置了背景之后,会发生listview的上边和下边有黑色的阴影。,使用android:fadingEdge="none" 即可解决。
2 自定义的listview,在拖动的时候出现一个空间黑色底色的情况,使用android:cacheColorHint=“#00000000”即可解决、
3 默认会显示选中listview的item为橙黄底色,有时候我们需要去掉这种效果:只需要设置android:listSelector属性即可,例如:android:listSelector="#00000000"设置点击为透明色。