导航:首页 > 操作系统 > android保存数组中

android保存数组中

发布时间:2022-09-23 15:19:13

1. android里面怎么把一组图片的id放在数组里面

int[] imageId = new int[] { R.drawable.c, R.drawable.b,R.drawable.cer_pic_1 };

2. 安卓:读取数据库保存到数组中

拿到cursor对象后调用Cursor类的方法即可
如:
String[] strs = new String[cursor.getCount()];
String columnName="";
int position = 0;
// cursor.moveToPosition(position);
cursor.moveToFirst();
while (cursor.moveToNext()) {
int index = cursor.getColumnIndex(columnName);
String str = cursor.getString(index);
strs[position++] = str;
}

3. android 如何将查询到的一列数组放到一维数组

可以直接拿来用啊

非要这么做的话使用list的toArray()方法

在程序中,我们往往习惯使用List这种集合类,但是程序中却要求需要传递一个数组,我们可以这样实现:

Long [] l = new Long[list.size()];
for(int i=0;i
l[i] = (Long) list.get(i);
这样的代码看上去似乎繁琐了一些,实际上List已经为我们提供了toArray()方法,但是如果使用时不注意,就会很容易发生ClassCastException,其产生的原因可以看下面的代码:

下面是网上找的
List list = new ArrayList();
list.add(new Long(1));
list.add(new Long(2));
list.add(new Long(3));
list.add(new Long(4));
Long[] l = (Long[])list.toArray();//这个语句会出现ClassCastException
for(int i=0; i
System.out.println(l[i].longValue());
在第6个语句会抛出ClassCastException异常。
其实,它的使用很简单,处理方式如下面代码:
Long [] l = (Long []) list.toArray(new Long[list.size()]);
注意的是:你要是传入的参数为9个大小,而list里面有5个object,那么其他的四个很可能是null , 使用的时候要注意

4. android开发中怎样用数组存放imageview图标

不就是动态设置布局么,说的那么复杂。 ImageView 设置一个ID 在Button的点击事件里面做如下处理: 1. 比如5张图片,那么int数组里面存他们的图片资源id,进行随机产生数字。然后根据不同的数字去int数组找到相应下标对象的图片资源id. 2. 调用 setBackgroud.. 方法设置背景图。

5. android中的蓝牙输入流的read(buffer)读到的是什么类型的数据如何把读到的数据放到一个数组中存起来

应该是字符串,string类型的。

6. 求助:1.android怎么把int型数组存入文件并保存在SD卡中 2.android怎么从文件中读取数据并存在数组中

用android自带的JSON库,
存档过程
int[] numberArray = {1,3,5,6,9,233,3255};
JSONArraynumbers=new JSONArray();
for(int number : numberArray){
numbers.put(number);
}

String jsonString= numbers.toString();

FileOutputStream fileOut=null;
OutputStreamWriter outStream =null;
try
{
fileOut =new FileOutputStream(saveFilePath,false);
outStream =new OutputStreamWriter(fileOut);
outStream.write(jsonString);
}
catch(Exception e)
{
}
finally
{
try
{
if(null!=outStream)
outStream.close();

if(null!=fileOut)
fileOut.close();
}
catch(Exception e)
{
}
}

读取过程差不多,new 一个FileInputStream 读取其中内容。
然后用这个字符串来初始化JSONArray,就可以得到结果。
记得给应用程序加上读写SD卡的权限。

7. android如何保存int[]数组到txt里

将int数组内容转换为字符串,然后以特定格式连接操作,然后存储。

  1. 将int数组内容取出,tempstring=""+int[i]+",";循环取出

  2. 将tempstring存储到txt文本中

  3. 以后读取文本时,以","分割 取出

8. Android如何存储一个ArrayList数组到本地

ArrayListlist=newArrayList();
SharedPreferencespreferences=getSharedPreferences("base64",
MODE_PRIVATE);
//创建字节输出流
ByteArrayOutputStreambaos=newByteArrayOutputStream();
try{
//创建对象输出流,并封装字节流
ObjectOutputStreamoos=newObjectOutputStream(baos);
//将对象写入字节流
oos.writeObject(list);
//将字节流编码成base64的字符窜
Stringlist_Base64=newString(Base64.encodeBase64(baos
.toByteArray()));
Editoreditor=preferences.edit();
editor.putString("list",list_Base64);

editor.commit();
}catch(IOExceptione){
//TODOAuto-generated
}
Log.i("ok","存储成功");

阅读全文

与android保存数组中相关的资料

热点内容
程序员培训学校排名 浏览:583
oppo手机如何解开微信的加密 浏览:32
学校论文答辩源码 浏览:60
rp在单片机中 浏览:172
linux软件运行命令 浏览:352
stcid加密程序 浏览:134
把解压包子放到水里 浏览:280
phpmongodb连接池 浏览:940
日本解压捏泡泡纸 浏览:115
环保参比算法 浏览:407
解压中的删掉是什么意思 浏览:763
王牌竞速什么时候能停止维修服务器 浏览:485
pdf阅读器官方 浏览:84
程序员那么爱心 浏览:304
字符a经过md5加密 浏览:416
绿色的小蝴蝶是个什么app 浏览:14
python编程输入数字输出年月日英文 浏览:627
程序员枪手 浏览:748
gm28服务器怎么设置 浏览:543
饿了么网站源码 浏览:332