⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choicedriveslist.java

📁 Android开发精典案例60个
💻 JAVA
字号:
package com.himi;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.Toast;

/**
 * 
 * @author Himi
 *
 */
public class ChoiceDrivesList extends Activity {
	//所有蓝牙设备的名字
	private String[] names;
	//提示
	private Toast toast;
	//对话框显示当前搜索到的蓝牙设备
	private AlertDialog.Builder dialog;

	public ChoiceDrivesList() {
		names = new String[MySurfaceView.vc_str.size()];
		for (int i = 0; i < MySurfaceView.vc_str.size(); i++) {
			names[i] = MySurfaceView.vc_str.elementAt(i);
		}
	}
	public void DisplayToast(String str, int type) {
		try {
			toast = null;
			if (type == 0) {
				toast = Toast.makeText(this, str, Toast.LENGTH_SHORT);
			} else {
				toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
			}
			toast.setGravity(Gravity.TOP, 0, 220);
			toast.show();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		dialog = new AlertDialog.Builder(ChoiceDrivesList.this);
		dialog.setIcon(android.R.drawable.btn_dialog);
		dialog.setSingleChoiceItems(names, 0, new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				MySurfaceView.deviceIndex = which;
			}
		}).setIcon(R.drawable.icon).setPositiveButton("连接", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialoginterface, int i) {
				DisplayToast("正在连接设备:" + MySurfaceView.vc_str.elementAt(MySurfaceView.deviceIndex), 1);
				MySurfaceView.gameState = MySurfaceView.CONNTCTING;
				new ConnectThread().start();
				finish();
			}
		}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialoginterface, int i) {
				finish();
			}
		}).setTitle("请选择连接设备!");
		dialog.show();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -