fragment pageview HorizontalScrollView
http://blog.csdn.net/lmj623565791/article/details/37970961
http://blog.csdn.net/huangyabin001/article/details/30053835
Dialog在Activity的显示和创建可以用Activity内的方法:
showDialog(int id);
protected Dialog onCreateDialog(int id)
2. 自定义的Dialog
layout_mydialog.xml 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:src="@drawable/ic_launcher"
android:layout_width="match_parent"
android:layout_height="64dp"
android:scaleType="center"
android:background="#FFFFBB33"
android:contentDescription="@string/app_name" />
<EditText
android:id="@+id/username"
android:inputType="textEmailAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp"
android:hint="username" />
<EditText
android:id="@+id/password"
android:inputType="textPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif"
android:hint="password"/>
</LinearLayout>
DialogTestActivity.java
package com.example.uitest;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnMultiChoiceClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class DialogTestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_dialog);
}
public void click1(View view){
Toast.makeText(this, "click1", 1000).show();
final String[] items = new String[]{"苹果","葡萄","香蕉"};
final boolean[] status = new boolean[]{true, false, true};
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("标题")
.setIcon(R.drawable.ic_launcher)
.setMultiChoiceItems(items, status, new OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Toast.makeText(DialogTestActivity.this, ""+items[which] + isChecked, 1000).show();
status[which] = isChecked;
}
})
.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(DialogTestActivity.this, " click 确定", 1000).show();
}
});
builder.show();
}
//自定义Dialog
public void click2(View view){
AlertDialog.Builder builder = new Builder(this);
//获得自定义的view
View viewDialog = View.inflate(this, R.layout.layout_mydialog, null);
final EditText usernameEt = (EditText) viewDialog.findViewById(R.id.username);
final EditText passwdEt = (EditText) viewDialog.findViewById(R.id.password);
builder.setView(viewDialog)
.setTitle("myself Dialog") //设置自定义的view
.setNegativeButton("取消", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String username = usernameEt.getText().toString();
String passwd = passwdEt.getText().toString();
Toast.makeText(DialogTestActivity.this, username + " : " + passwd, 1000).show();
}
});
builder.show();
}
}
1. 对话框示例代码
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- /**
- * 确定取消对话框
- *
- * @param view
- */
- public void click1(View view) {
- // 1.创建一个对话框的构造器.
- AlertDialog.Builder builder = new Builder(this);
- builder.setTitle("java培训标题");
- builder.setIcon(R.drawable.ic_launcher);
- builder.setMessage("想打开官方网站么?");
- builder.setPositiveButton("确定", new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_VIEW);
- intent.setData(Uri.parse("http://edu.csdn.net"));
- startActivity(intent);
- }
- });
- builder.setNegativeButton("取消", new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // 默认实现, 点击后 关闭对话框
- }
- });
- // builder.create().show();
- builder.show();
- }
- /**
- * 单选对话框
- *
- * @param view
- */
- public void click2(View view) {
- // 1.创建一个对话框的构造器.
- AlertDialog.Builder builder = new Builder(this);
- builder.setTitle("你想吃什么");
- final String[] items = new String[] { "苹果", "葡萄", "香蕉" };
- builder.setSingleChoiceItems(items, 1, new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(MainActivity.this, "您选择了吃" + items[which], 0)
- .show();
- dialog.dismiss();
- }
- });
- // builder.create().show();
- builder.show();
- }
- /**
- * 多选对话框
- *
- * @param view
- */
- public void click3(View view) {
- // 1.创建一个对话框的构造器.
- AlertDialog.Builder builder = new Builder(this);
- builder.setTitle("你想吃什么");
- final String[] items = new String[] { "苹果", "葡萄", "香蕉" };
- final boolean[] status = new boolean[] { true, false, true };
- builder.setMultiChoiceItems(items, status,
- new OnMultiChoiceClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which,
- boolean isChecked) {
- if (isChecked) {
- Toast.makeText(MainActivity.this,
- items[which] + "被选中了", 0).show();
- } else {
- Toast.makeText(MainActivity.this,
- items[which] + "被取消选中了", 0).show();
- }
- status[which] = isChecked;
- }
- });
- builder.setPositiveButton("确定", new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // todo:遍历数组 查看状态
- }
- });
- // builder.create().show();
- builder.show();
- }
- /**
- * 进度条对话框
- *
- * @param view
- */
- public void click4(View view) {
- ProgressDialog pd = new ProgressDialog(this);
- pd.setTitle("请稍后");
- pd.setMessage("正在后台处理...");
- pd.show();
- new Thread(){
- public void run(){
- Thread.sleep(2000);
- pd.dismiss();
- }
- }.start();
- }
- /**
- * 显示进度的进度条对话框
- *
- * @param view
- */
- public void click5(View view) {
- final ProgressDialog pd = new ProgressDialog(this);
- pd.setTitle("请稍后");
- pd.setMessage("正在后台处理...");
- pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- pd.setMax(100);
- new Thread(){
- public void run() {
- for(int i = 0;i<100;i++){
- pd.setProgress(i);
- try {
- Thread.sleep(30);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- pd.dismiss();
- };
- }.start();
- pd.show();
- }
- }