Android零碎知识(一)
public abstract Resources getResources ()
Return a Resources instance for your application's package.
BitmapFactory
extends Object java.lang.Object
↳ android.graphics.BitmapFactory Class Overview -------------------------------------------------------------------------------- Creates Bitmap objects from various sources, including files, streams, and byte-arrays.
public void translate (float dx, float dy)
Added in API level 1
Preconcat the current matrix with the specified translation When working with matrices, the word concatenation refers to multiplication. Since matrix multiplication is not commutative, there is a separate word for backwards multiplication.
Pre-concatenating a to b means setting a = b × a. (As opposed to a = a × b, which will give a different matrix) The canvas maintains a matrix and the canvas is manipulated by methods which are well defined in OpenGL
三种列表对话框:setItems,setItems,setMultiChoiceItems。
在 接口DialogInterface.OnClickListener的抽象方法
public abstract void onClick (DialogInterface dialog, int which) 中的参数which:The button that was clicked (e.g. BUTTON1)
or the position of the item clicked
既能监听列表项(>=0),又能监听按钮(<=0)
BUTTON_NEGATIVE=-2,BUTTON_NEUTRAL=-3,BUTTON_POSITIVE=-1;
public AlertDialog.Builder setSingleChoiceItems (CharSequence[] items, int checkedItem, DialogInterface.OnClickListener listener)
其中参数checkedItem specifies which item is checked. If -1 no items are checked.因为有默认选项,onclick方法若不点击列表项,这个默认值就获取不到,所以在onclick方法里需要设置index的默认值为1。下面的程序是在构造方法传入1的。
另外注意在多选列表对话框中是如何获得用户选择的列表项,先得到对话框的Listview对象,扫描的方式
package net.blogjava.mobile; import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView; public class Main extends Activity implements OnClickListener
{
private String[] provinces = new String[]
{ "辽宁省", "山东省", "河北省", "福建省", "广东省", "黑龙江省" };
private ButtonOnClick buttonOnClick = new ButtonOnClick(1);
private ListView lv = null;
private void showListDialog()
{
new AlertDialog.Builder(this).setTitle("选择省份").setItems(provinces,
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which)
{
final AlertDialog ad = new AlertDialog.Builder(
Main.this).setMessage(
"您已经选择了: " + which + ":" + provinces[which])
.show();
android.os.Handler hander = new android.os.Handler();
hander.postDelayed(new Runnable()
{
@Override
public void run()
{
ad.dismiss(); }
}, 5 * 1000); }
}).show();
} private void showSingleChoiceDialog()
{ new AlertDialog.Builder(this).setTitle("选择省份").setSingleChoiceItems(
provinces, 1, buttonOnClick).setPositiveButton("确定",
buttonOnClick).setNegativeButton("取消", buttonOnClick).show(); } private void showMultiChoiceDialog()
{ AlertDialog ad = new AlertDialog.Builder(this)
.setIcon(R.drawable.image).setTitle("选择省份")
.setMultiChoiceItems(provinces, new boolean[]
{ false, true, false, true, false, false },
new DialogInterface.OnMultiChoiceClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton, boolean isChecked)
{ }
}).setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,
int whichButton)
{
int count = lv.getCount();
String s = "您选择了:";
for (int i = 0; i < provinces.length; i++)
{ if (lv.getCheckedItemPositions().get(i))
s += i + ":"
+ lv.getAdapter().getItem(i)
+ " "; }
if (lv.getCheckedItemPositions().size() > 0)
{
new AlertDialog.Builder(Main.this)
.setMessage(s).show();
}
else
{
new AlertDialog.Builder(Main.this)
.setMessage("您未选择任何省份").show(); } }
}).setNegativeButton("取消", null).create();
lv = ad.getListView();
ad.show(); } private class ButtonOnClick implements DialogInterface.OnClickListener
{
private int index; public ButtonOnClick(int index)
{
this.index = index;
} @Override
public void onClick(DialogInterface dialog, int whichButton)
{
if (whichButton >= 0)
{
index = whichButton;
// dialog.cancel();
}
else
{
if (whichButton == DialogInterface.BUTTON_POSITIVE)
{
new AlertDialog.Builder(Main.this).setMessage(
"您已经选择了: " + index + ":" + provinces[index]).show();
}
else if (whichButton == DialogInterface.BUTTON_NEGATIVE)
{
new AlertDialog.Builder(Main.this).setMessage("您什么都未选择.")
.show(); }
} } } @Override
public void onClick(View view)
{
switch (view.getId())
{
case R.id.btnListDialog:
{
showListDialog();
break;
}
case R.id.btnSingleChoiceDialog:
{
showSingleChoiceDialog();
break;
}
case R.id.btnMultiChoiceDialog:
{
showMultiChoiceDialog();
break;
}
}
} @Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnListDialog = (Button) findViewById(R.id.btnListDialog);
Button btnSingleChoiceDialog = (Button) findViewById(R.id.btnSingleChoiceDialog);
Button btnMultiChoiceDialog = (Button) findViewById(R.id.btnMultiChoiceDialog);
btnListDialog.setOnClickListener(this);
btnSingleChoiceDialog.setOnClickListener(this);
btnMultiChoiceDialog.setOnClickListener(this);
}
}
Android零碎知识(一)的更多相关文章
- Android零碎知识之Style and Theme
Android的styles资源文件中存在了我们在应用中定义的各种style,它们都是以style开始的元素,包含许多属性的集合.但我们一般般它们分为style和theme,那它们有什么区别呢? 一. ...
- Android零碎知识
1.当启动一个APP时按下后退键会调用onBackPressed方法. 如果想要屏蔽后退键只需要重写onBackPressed方法如下即可: @Override public void onBackP ...
- Xamarin Android教程Android基本知识版本介绍与系统介绍
Xamarin Android教程Android基本知识版本介绍与系统介绍 Xamarin Android教程Android基本知识版本介绍与系统介绍,开发Andriod有时候不像iOS一样轻松,因为 ...
- [转]【eoeAndroid索引】史上最牛最全android开发知识汇总
一.开发环境搭建 (已完成) 负责人:kris 状态:已完成 所整理标签为:搭建 SDK JDK NDK Eclipse ADT 模拟器 AVD 调试器(DEBUG) DDMS 测试 日志 Logca ...
- Android基本知识
Android是Google公司于2007年发布的基于Linux内核的手机操作系统.应用层主要以java为编程语言,应用层分为两层,函数层(Library) 和虚拟机(Virtual).中间 ...
- 【Xamarin开发 Android 系列 4】 Android 基础知识
原文:[Xamarin开发 Android 系列 4] Android 基础知识 什么是Android? Android一词的本义指“机器人”,同时也是Google于2007年11月5日宣布的基于Li ...
- 第01讲- Android背景知识
第01讲Android背景知识 Android是基于Linux系统 Android系统框图 : 第一.操作系统层(OS) 第二.各种库(Libraries)和Android 运行环境(RunTime) ...
- 写给Android App开发人员看的Android底层知识(1)
这个系列的文章一共8篇,我酝酿了很多年,参考了很多资源,查看了很多源码,直到今天把它写出来,也是战战兢兢,生怕什么地方写错了,贻笑大方. (一)引言 早在我还是Android菜鸟的时候,有很多技术我都 ...
- 【Python】 零碎知识积累 II
[Python] 零碎知识积累 II ■ 函数的参数默认值在函数定义时确定并保存在内存中,调用函数时不会在内存中新开辟一块空间然后用参数默认值重新赋值,而是单纯地引用这个参数原来的地址.这就带来了一个 ...
随机推荐
- Bootstrap基础学习(二)—表单
一.表单 1.基本格式 <!-- 基本格式 --> <form> <div class="form-group"> <label>姓 ...
- Cesium之球心坐标与本地坐标
1球心坐标(ECEF)与本地坐标(NEU) 假如你来到一个陌生城市,你很可能需要问路.通常会告诉你向北走100米,右转,向东走100米,理解起来很直观.你给儿子买了一个地球仪,你从北京(39,115) ...
- require.js入门
小颖目前所在的公司在用require.js,小颖一只说要写个小demo,今天抽空把自己写的小demo分享出来,希望对初学者有一些帮助,嘻嘻 学习资料: CSDN上的一篇文章:使用RequireJS优化 ...
- oracle定时执行一个存储过程
首先需要新建存储过程 一 存储过程: create or replace procedure Insertdata is begin INSERT INTO tab_dayta select * fr ...
- Android Gradle 指定 Module 打包
Android Gradle 指定 Module 打包 项目中有许多的可以直接独立运行的 Module ,如何在 Gradle 中将签名文件配置好了,那么就不需要普通的手动点击 Generate Si ...
- 本地yum服务搭建
1.准备linux ISO系统镜像文件 (例如:rhel-server-5.5-i386-dvd.iso) 2.linux虚拟机(centos 7 192.168.50.24 ),启动sshd服务 ...
- php 启动过程 - reqeust RINIT 过程
php 启动过程 - reqeust RINIT 过程 概述 apache 接收到请求之后, 交给 php 处理 php 模块在接收到请求后, 会对请求进行初始化, 及 RINIT 过程 调用触发 a ...
- JavaEE开发之SpringMVC中的自定义拦截器及异常处理
上篇博客我们聊了<JavaEE开发之SpringMVC中的路由配置及参数传递详解>,本篇博客我们就聊一下自定义拦截器的实现.以及使用ModelAndView对象将Controller的值加 ...
- HTML5 模拟现实物理效果
Ball Pool 是一个基于 HTML5 技术的实验,模拟现实物理效果,让你在 Web 中感受自然物体的运动.玩法介绍:可以随意拖动圆球.点击页面背景.晃动浏览器.双击页面背景或者按住鼠标左键,有不 ...
- Angular2.js——表单(下)
这部分是接表单上部分的内容,主要内容有: 1.添加自定义的CSS来提供视觉反馈: 2.显示和隐藏有效性验证的错误信息: 3.使用ngSubmit处理表单提交: 4.禁用表单提交按钮. 添加自定义的CS ...