導航:首頁 > 操作系統 > 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保存數組中相關的資料

熱點內容
ai文件pdf 瀏覽:907
騰訊雲伺服器掛載混合雲 瀏覽:758
智能小車用什麼單片機 瀏覽:463
java怎麼給窗口關閉 瀏覽:940
列舉51單片機的定址方式 瀏覽:706
剪輯app怎麼寫長篇文字 瀏覽:400
app專屬流量過月租怎麼不更新 瀏覽:654
王者程序員都有誰 瀏覽:76
給牛換腳掌解壓 瀏覽:387
圍棋有多少種演算法 瀏覽:602
unity資源包在哪個文件夾 瀏覽:704
阿里雲伺服器遠程鏈接不成功 瀏覽:482
文件系統pdf 瀏覽:766
原神安卓區服什麼意思 瀏覽:37
貝殼app怎麼線上發布 瀏覽:159
如何挑選安卓系統機頂盒 瀏覽:53
安卓快充使用有什麼注意事項 瀏覽:909
黑馬程序員的雲計算網課 瀏覽:947
endnotestyle文件夾怎麼導入 瀏覽:460
講解少兒編程演講會開頭 瀏覽:425