网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

android赋值的简单介绍

android数据库怎么样把Cursor的值 赋值给字符串

调用cursor的getString方法(参考代码见下面)

罗城网站建设公司创新互联,罗城网站设计制作,有大型网站制作公司丰富经验。已为罗城上1000家提供企业网站建设服务。企业网站搭建\成都外贸网站制作要多少钱,请找那个售后服务好的罗城做网站的公司定做!

在while循环里,如果cursor.moveToNext()能移动到下一条

就代表游标对象里有数据。然后调用cursor的getString()方法把cursor的复制给字符串。

public ListBlackBean findAll() {

SQLiteDatabase db = helper.getReadableDatabase();

ListBlackBean blackBeans = new ArrayListBlackBean();

Cursor cursor = db.query("blackNumber", new String[]{"number", "mode"}, null, null, null, null, null);

while (cursor.moveToNext()) {

BlackBean blackNumberInfo = new BlackBean();

blackNumberInfo.setNumber(cursor.getString(0));

blackNumberInfo.setMode(cursor.getString(1));

blackBeans.add(blackNumberInfo);

}

cursor.close();

return blackBeans;

}

android 数组里面数据有name date 怎么赋值到model里面去

java之数组

数组概述:

1、数组可以看成是多个相同数据类型数据的组合,对这些数据的统一管理。

2、数组变量属引用类型,数组也可以看成是对象,数组中的每个元素相当于该对象的成员变量。

3、数组中的元素可以是任何类型,包括基本类型和引用类型。

一维数组的声明:

1、一维数组的声明方式:

type var[]; 或type[] var;

例如:

int a1[]; int[] a2; double b[]; Person[] p1; String s1[];

2、java语言中声明数组时不能指定其长度(数组中元素的个数),例如:

int a[5];//非法

数组对象的创建:

1、java中使用关键字new 创建数组对象,格式为:

数组名 = new 数组元素类型[数组元素个数];

例如:

public class TestArray{

public static void main(String args[]){

int[] arr;

arr = new int[5];

for(int i=0;i5;i++){

arr[i] = i;

System.out.println(arr[i]);

}

}

}

2、元素为引用类型的数据(注意:元素为引用数据类型的数组中的每一个元素都需要实例化)

例如:

public class TestArray{

public static void main(String args[]){

Date[] date;

date = new Date[3];

for(int i=0; i3; i++){

date[i] = new Date(2014,10,25);

System.out.println(date[i].year+"年,"+date[i].month+"月,"+date[i].day+"日!");

}

}

}

class Date{

int year,month,day;

public Date(int year,int month,int day){

this.year = year;

this.month = month;

this.day = day;

}

}

数组初始化:

1、动态初始化:

数组定义与为数组元素分配空间和赋值的操作分开进行,例如:

public class TestArray{

public static void main(String args[]){

int[] arr = new int[3]; //数组定义

arr[0]=1; //数组初始化

arr[1]=2;

arr[2]=3;

Date[] date = new Date[3]; //数组定义

date[0] = new Date(2014,10,25); //数组初始化

date[1] = new Date(2014,10,25);

date[2] = new Date(2014,10,25);

}

}

class Date{

int year,month,day;

public Date(int year,int month,int day){

this.year = year;

this.month = month;

this.day = day;

}

}

2、静态初始化

在定义数组的同时就为数组元素分配空间并赋值,例如:

public class TestArray{

public static void main(String args[]){

int a[] = {1,2,3};

Date[] date = {new Date(2014,10,25), new Date(2014,10,26), new Date(2014,10,27)};

}

}

class Date{

int year,month,day;

public Date(int year,int month,int day){

this.year = year;

this.month = month;

this.day = day;

}

}

3、数组元素的默认初始化:

数组时引用类型,它的元素相当于类的成员变量,因此数组分配空间后,每个元素也被按照成员变量的规则被隐式初始化,例如:

public class TestArray{

public static void main(String args[]){

int[] a = new int[3];

Date[] date = new Date[3];

System.out.println(a[2]);

System.out.println(date[2]);

}

}

class Date{

int year,month,day;

public Date(int year,int month,int day){

this.year = year;

this.month = month;

this.day = day;

}

}

数组元素的引用:

1、定义并用运算符new为之分配空间后,才可以引用数组中的每个元素,数组元素的引用方式为:

①、arrayName[index]

index为数组元素下标,可以使整形常亮或整形表达式。如:

a[3], b[i], c[6*i];

②、数组元素的下标从0开始;长度为n的数组的合法下标取值范围为:

0~n-1;

2、每个数组都有一个属性lendth(注:这里length是一个属性,不是方法,没有加括号(),我们这里特别说明是为了和String的length()方法做区别)指明他的长度,例如:

a.length的值为数组a的长度(元素个数)

注:

public static void main(String args[]){}

我们每个类中的主函数也有一个数组,名叫srgs,那么这个数组时干嘛用的呢?这个数组就好比,我们在命令行中注入 ipconfig -all 中的all. 我们可以在输入 java TestArray(类名) 23,12,aa,bbb 这个跟几个参数。然后可以在代码中输出来看到。

注(基础类型的包装类):

基础类型的包转类, 基础类型是分配在栈内存中的 , 包装类是分配在堆空间里面的 。

基础类型的包装类有:Boolean---boolean 、 Byte---byte 、 Character---char 、 Double---double 、 Float---float 、 Integer---int 、 Long--- long 、 Short---short 通常我们使用parsexxx()方法来将string类型转换为我们想要的数据类型。我们也可以使用string类型的valueOf()方法将想要的 数据类型转换为string类型。

下面我们举一个args[]参数和基础类型包装类一起使用的例子,用来计算+-x/:

public class TestArgs{

public static void main(String args[]){

if(args.length3){

System.out.println("error~~~");

System.exit(0);

}

double b1 = Double.parseDouble(args[0]);

double b2 = Double.parseDouble(args[2]);

double b = 0;

if(args[1].equals("+")){

b = b1 + b2;

}else if(args[1].equals("-")){

b = b1-b2;

}else if(args[1].equals("x")){

b = b1*b2;

}else if(args[1].equals("/")){

b = b1/b2;

}else{

System.out.println("error operation!!!");

}

System.out.println(b);

}

}

下面举一个用ars输入10个数,并且用选择排序,从小到大排序的示例:

public class TestSortInt{

public static void main(String args[]){

int[] a = new int[args.length];

for(int i=0; iargs.length; i++){

a[i] = Integer.parseInt(args[i]);

}

int k,temp;

for(int i=0; ia.length; i++){

k = i;

for(int j=i+1; ja.length; j++){

if(a[k]a[j]){

k=j;

}

}

if(k!=i){

temp = a[i];

a[i] = a[k];

a[k] = temp;

}

}

for(int i=0; ia.length; i++){

System.out.print(a[i] + " ");

}

}

}

下面我们用数组里面装一个日期类型做排序的示例,用了冒泡排序。

public class TestDateSort{

public static void main(String args[]){

Date[] date = new Date[5];

date[0] = new Date(2006,5,4);

date[1] = new Date(2006,7,4);

date[2] = new Date(2008,5,4);

date[3] = new Date(2004,5,9);

date[4] = new Date(2006,5,4);

bubbleSort(date);

for(int i=0; i date.length; i++){

System.out.println(date[i]);

}

}

public static Date[] bubbleSort(Date[] a){

int len = a.length;

for(int i=len; i=1; i--){

for(int j=0; ji-1; j++){

if(a[j].compare(a[j+1])0){

Date temp = a[j+1];

a[j+1] = a[j];

a[j] = temp;

}

}

}

return a;

}

}

class Date{

private int year,month,day;

public Date(int year,int month,int day){

this.year = year;

this.month = month;

this.day = day;

}

public int compare(Date date){

return yeardate.year?1

:yeardate.year?-1

:monthdate.month?1

:monthdate.month?-1

:daydate.day?1

:daydate.day?-1

:0;

}

public String toString(){

return "year,month,day ---- " +year+" - "+month+" - "+day;

}

}

Android怎么对控件数组的每一个元素赋值

Android可以遍历每一个控件,使用instanceof判断类型进行相应的赋值。

比如:Button button = new Button(this);

ImageView textView = new ImageView(this);

View[] views = new View[] {button, textView};

for (View itemview : views) {

if (itemview instanceof TextView) {

System.out.println("This is a imageView");

}

if (itemview instanceof Button) {

System.out.println("This is a button");

}

}

但是要注意一下继承关系,比如Button extends TextView。因此Button 也会走TextView的判断方法,因此需要把子类判断放在前面,得到合适的即continue;

for (View itemview : views) {

if (itemview instanceof Button) {

System.out.println("This is a button");

continue

}

if (itemview instanceof TextView) {

System.out.println("This is a TextView");

continue;

}

if (itemview instanceof TextView) {

System.out.println("This is a imageView");

continue;

}

}

怎么给bitmap赋值 android

Bitmap是Android系统中的图像处理的最重要的类之一。用它可以获取图像文件信息,对图像进行旋转,剪切,放大,缩小等操作。

Bitmap代表一张位图,使我们在开发中常用的资源,下面就对Bitmap进行简单的介绍。

Bitmap的获取方法:

1、使用BitmapDrawable

BitmapDrawable里封装的图片就是一个Bitmap对象,我们要把Bitmap包装成BitmapDrawable对象,可以调用BitmapDrawable的构造方法:

BItmapDrawbale drawable = new BItmapDrawable(bitmap);

如果要获取BitmapDrawable所包装的Bitmap对象,则可调用BitmapDrawable的getBitmap()方法:

Bitmap bitmap = drawbale.getBitmap();

2、Bitmap提供了一些静态方法来创建Bitmap对象(仅列举几个):

createBitmap(Bitmap source,int x,int y,int width,int height):从原位图source的指定坐标(x,y)开始,从中挖取宽width,高heigtht的一块出来,创建新的Bitmap对象。

createScaledBitmap(Bitmap source,int width,ing height,boolean fliter):对源位图进行缩放,缩放称宽width,高heigth的新位图。

createBitmap(int width,int height,Bitmap.Config config):创建一个宽width,高height的可变的新位图。

createBitmap(Bitmap source, int x,int y,int width,int height ,Matrix m,boolean fliter):从源位图source的指定坐标(x,y)开始,挖取宽width,高height的一块来,创建新的Bitmap对象,并按照Matrix指定的规则进行变换。

3、通过对资源文件的解析获取Bitmap对象

在这里就要用到BitmapFactory这个工具类,提供的方法如下:

decodeByteArray(byte[] data, int offset,int length):从指定字节数组的offset位置开始,将长度为length的字节数据解析成Bitmap对象。

decodeFIle(String pathName):从pathName指定的文件中解析、创建Bitmap对象。

decodeFileDescriptor(FileDescriptor fd):用于从FileDescriptor对应的文件中解析、创建Bitmap对象。

decodeResource(Resource res,int id):用于根据给定的资源ID从指定的资源文件中解析、创建Bitmap对象。

decodeStream(InputStream is):用于从指定输入流中介解析、创建Bitmap对象。

但是,在系统不断的解析、创建Bitmap的过程中,可能会由于内存小或其他原因,导致程序运行时发生OutOfMemory错误。

为此,Android为Bitmap提供了内存回收方法:

void recycle():强制回收Bitmap对象。

还有用于判断Bitmap 对象是否被回收的方法:

boolean isRecycle();

如果Android应用需要访问系统相册,都需要借助BitmapFactory解析、创建Bitmap对象。

4 从安卓无忧中看bitmap的几种例子,下面是加载bitmap的例子,可以看里面的源码:

如果您对答案满意,请您关注一下名字中微博。

二维数组 安卓版怎么赋值

1,创建二维数组语句:int[][] array = new int[3][3];

2,直接创建二维数组并赋值语句:int[][] array ={{1,2,3,4,5},{1,2,3,4,5},{1,2,3,4,5}} ;

二维数组,也可以理解为用一维数组保存的元素为一维数组。对于三维数组,等等,都可以这样划分。不过我们在编程中使用三维以上的数组比较少。因为那样使用起来非常不方便。下面我们来学习二维数组的声明。其声明同一位数组一样,可以先声明再分配内存,也可以声明时分配内存

第一种,先声明再分配内存的方式

数组声明: 数据类型 数组名[][];

内存分配: 数组名 = new 数据类型[行的个数][列的个数];

举例: 假如我们需要统计一个象棋上放的是黑棋还是白棋。这时,我们可以建立一个坐标,即以象棋盘的两边建立坐标轴。这时,我们可以这样定义这个二维数组:

声明数组: int Chess[][];

内存分配 Chess= new int[64][64];

第二种,即声明时即分配内存的方式。

使用格式是: 数据类型 数组名[][] =new 数据类型 [行的个数][列的个数];

使用上个步骤中的例子,我们可以将数组的声明和分配内存写成以下方式:

声明即分配内存:int Chess[][] = new int[64][64];

二维数组的赋值,同一维数组类似。只是在{}中的每个元素又是每个一维数组。如下格式:

数据类型 数据名[][]={

{值1,值2,值3,值4 }, //第一行数据

{值5,值6,值7,值8}, //第二行数据

...,

}

二维数组中,可以有列数不相等的数组。即每一行的列数不同时。我们需要对每一行进行赋值。

对于这两种二维数组。我们分别来进行分别举例进行赋值。第一种是:列数相同的数组

其赋值格式如下:

String ClassRoom[][]={

{"小王","小李","小张"},

{"小红","小明","小花"},

}

即第一行的人数和第二行的人数相同。

第二种:即列数不相等的数组的赋值格式如下:

String ClassRoom[][]={

{"小王","小李","小张"},

{"小红","小明","小花"},

{"小雨","小风","小平","小雷"},

{"小单"}

}

看上述例子。对于不同的行,其相应的列数是不同的。

android从服务器取出来的所有数据怎么赋值给textview

Android读写数据库代码比较多,以下为基本步骤:

创建数据库,并读写/ol创建一个名为Test的数据库,并返回一个SQLiteDatabase对象mSQLiteDatabasemSQLiteDatabase=this.openOrCreateDatabase("Test",MODE_PRIVATE,null);通过execSQL方法来执行一条SQL语句。String CREATE_TABLE="create table 表名(列名,列名,……)";mSQLiteDatabase.execSQL(CREATE_TABLE);

2.以使用insert方法来添加数据,但是insert方法要求把数据都打包到ContentValues中,ContentValues其实就是一个Map,Key值是字段名称,Value值是字段的值。通过ContentValues的put方法就可以把数据放到ContentValues对象中,然后插入到表中去。具体实现如下:pre t="code" l="java"ContentValues cv=new ContentValues();

cv.put(TABLE_NUM,1);

cv.put(TABLE_DATA,"测试数据库数据");

mSQLiteDatabase.insert(Test,null,cv);

//同样可以使用execSQL方法来执行一条“插入“的SQL语句

String INSERT_DATA="insert into 表名(列名,……) values (值,……)";

mSQLiteDatabase.execSQL(INSERT_DATA);

3.创建TextView对象,并赋值TextView textView = (TextView) finadViewById(R.id.textView);textView.setTextView(text);


分享文章:android赋值的简单介绍
网页路径:http://bjjierui.cn/article/hogcsp.html

其他资讯