Android开发之列表对话框的使用
2013-12-30 20:40
477 查看
在values.xml新建interest.xml文件
<?xml
version="1.0" encoding="utf-8"?>
<resources>
<string-array
name="selinterest">
<item>篮球</item>
<item>游泳</item>
<item>足球</item>
<item>游戏</item>
</string-array>
</resources>
main.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<Button
android:id="@+id/interest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="选择爱好" />
<TextView
android:id="@+id/mysel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
.java文件
package
com.example.dialogdemo;
import
android.os.Bundle;
import
android.app.Activity;
import
android.app.AlertDialog;
import
android.app.Dialog;
import
android.content.DialogInterface;
import
android.view.KeyEvent;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.TextView;
public class MainActivity
extends Activity {
private Button
button=null;
private View
interests=null;
private TextView
mysel=null;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.button=(Button)
super.findViewById(R.id.interest);
this.mysel=(TextView)
super.findViewById(R.id.mysel);
//为我们的图片添加事件
this.button.setOnClickListener(new
OnClickListenerImp());
}
public class OnClickListenerImp
implements OnClickListener{
public void onClick(View arg0)
{
Dialog dialog=new
AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_launcher)
.setTitle("选择您的兴趣爱好")
.setNegativeButton("取消", new
DialogInterface.OnClickListener() {
public void
onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method
stub
}
})
//设置多选提示框
.setItems(R.array.selinterest,
new DialogInterface.OnClickListener() {
public void
onClick(DialogInterface dialog, int which) {
MainActivity.this.mysel.setText("您选择的爱好是"+MainActivity.this.getResources().getStringArray(R.array.selinterest)[which]);
}
})
.create();
dialog.show();
}
}
}
相关文章推荐
- Android开发基础之AlertDialog的列表对话框的使用
- Android UI开发第三十六篇——使用Volley加载图片列表
- Android开发之:在对话框中使用进度条
- 【Android 开发】:UI控件之 ListView 列表控件的使用(二)
- 【Android 开发】:UI控件之 AlertDialog 对话框控件的的使用(二)
- 【Android开发】消息提示框与对话框-使用Notification在状态栏上显示通知
- android中列表选项、单选选项、多选选项对话框的使用
- android中列表选项、单选选项、多选选项对话框的使用
- 【Android开发】消息提示框与对话框-使用Toast显示消息提示框
- Android开发中Dialog对话框的使用
- 【Android 开发】:UI控件之 Spinner 下拉列表控件的使用
- 【Android 开发】:UI控件之 Dialogs 对话框控件的的使用(三)
- 【Android 开发】:UI控件之 ListView 列表控件的使用
- Android开发之使用BaseAdapter的notifyDataSetChanged()无法更新列表
- Android使用AlertDialog实现的信息列表单选、多选对话框功能
- Android开发中Dialog对话框的使用
- 【Android开发】消息提示框与对话框-使用AlertDialog创建对话框
- Android开发之使用活动显示对话框
- Android开发中Dialog对话框的使用
- Android使用RadioButton结合ListView显示对话框单选按钮列表