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數組內容轉換為字元串,然後以特定格式連接操作,然後存儲。
將int數組內容取出,tempstring=""+int[i]+",";循環取出
將tempstring存儲到txt文本中
以後讀取文本時,以","分割 取出
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","存儲成功");