导航:首页 > 操作系统 > 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保存数组中相关的资料

热点内容
磁力计校正算法 浏览:491
解压缩后变小了 浏览:957
智友文件夹 浏览:81
android操作系统开发的操作系统 浏览:478
原神手机怎么改b站服务器 浏览:296
桩基箍筋加密区高度规范 浏览:91
手机樱花动漫app怎么用 浏览:382
php科学计数法转换 浏览:642
sip认证算法 浏览:785
androidapp卡顿原因 浏览:905
25编程器电路 浏览:849
安卓九是什么东西 浏览:939
隐藏nodejs命令行窗口 浏览:62
人体与写生素描pdf 浏览:883
java集合性能 浏览:143
单片机三线通信 浏览:209
昆山ug编程培训学费 浏览:628
黄色app怎么盈利的 浏览:957
怎么修改linux密码 浏览:703
国家发展中心app长什么样子 浏览:242