⑴ android listview 怎麼添加數據
是添加還是填充,填充的話用adapter填充,添加的話,在list.add添加數據後,用adapter.notifyDataSetChanged();來刷新就行
⑵ android 數組添加數據
這樣直接定義了數組的長度,是沒有辦法增加的
如果想要增加的話:
java">intinSize=2;//增加的個數
doubletemp[]=newdouble[doubles.length+inSize];//臨時數組
System.arrayCopy(doubles,0,temp,0,doubles.length);//把數組doubles拷貝到temp
temp[5]=6;
temp[6]=7;
doubles=temp;
⑶ 求助: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卡的許可權。
⑷ android 數組添加數據
追加一個 數 之後再 執行一下 排序 就可以了 參考 排序 方法 ArrayList arr=new ArrayList(); int Temp;arr.Add(..).... for(int i=0;i<N;i++) { for(int j=0;j<N-i-1;j++) { if(int.Parse(arr[j+1])<int.Parse(arr[j])) { Temp=int.Parse(arr[j+1]); arr[j+1]=int.Parse(arr[j]); arr[j]=Temp; } } }
⑸ android中怎麼把數組的內容在ListView中顯示
數組的內容顯示在list上需要三大步:
1.ListVeiw 用來展示列表的View。
2.適配器Adapter 用來把數據映射到ListView上。
3.數據 具體的將被映射的字元串,圖片,或者基本組件。
根據列表的適配器類型,列表分為三種,ArrayAdapter,SimpleAdapter和SimpleCursorAdapter
如果僅僅將數組的內容顯示到ListView 上ArrayAdapter就夠了
public classTest extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] sw = new String[10];
for (int i = 0; i < 10; i++) {
sw[i] = "List_" + i;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,sw);//使用系統已經實現好的xml文件simple_list_item_1
setListAdapter(adapter);
}
}
//這樣就容易的用系統已經實現的layout很快速的實現了listview載入數組sw,這樣實現只能簡單的將數組中的數據列在每一行上,同一行上不能添加其他東西,比如:圖片/按鍵等
如果在同一行上進行不同的操作,可以用SimpleAdapter
如果在同一行上添加對象之類的,比如新浪微薄上每一條微薄、人人上每一條分享之類的,就要自己寫類繼承與BaseAdapter重寫其中的getView方法
祝你好運~~
⑹ android怎麼在array配置文件中添加圖片資源數組
Android R.array是提取XML資源文件中String數組的方法。
1. R.array的提供代碼:
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<string-arrayname="city">
<item>廈門市</item>
<item>福州市</item>
<item>泉州市</item>
<item>漳州市</item>
<item>龍岩市</item>
</string-array>
</resources>
2.代碼中數組的提供方式:
Resources res =getResources();
String[] city=res.getStringArray(R.array.city);
3.圖片數組,需要在drawable目錄下創建一個animation.xml
<?xmlversion="1.0"encoding="utf-8"?>
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="true">
<itemandroid:drawable="@drawable/icon1"android:ration="150"></item>
<itemandroid:drawable="@drawable/icon2"android:ration="150"></item>
<itemandroid:drawable="@drawable/icon3"android:ration="150"></item>
<itemandroid:drawable="@drawable/icon4"android:ration="150"></item>
<itemandroid:drawable="@drawable/icon5"android:ration="150"></item>
<itemandroid:drawable="@drawable/icon6"android:ration="150"></item>
</animation-list>
4.提取方式直接在layout中android:src="@drawable/animation" 即可引用。
⑺ android 怎麼把資料庫表數據 寫入二維數組
這個例子是將資料庫中的數據存儲到集合中
List<ContactInfo> list = new ArrayList<ContactInfo>();//ContactInfo實體類
SQLiteDatabase db = dbOpentHlper.getReadableDatabase();
String sql = "select * from contactinfo";
Cursor cursor = db.rawQuery(sql, null);
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("_id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String qq = cursor.getString(cursor.getColumnIndex("qq"));
String msn = cursor.getString(cursor.getColumnIndex("msn"));
String phone = cursor.getString(cursor.getColumnIndex("phone"));
list.add(new ContactInfo(id, name, qq, msn, phone));
}
⑻ 安卓數組在指定位置插入數據怎麼刷新設配器
expandablelistview的用法和listview的用法差不多,也需要用適配器來添加數據,但是他有兩個視圖,一個父視圖,一個子視圖,你只要把sharedpreferance中的數據放到你想要顯示的視圖中就行了
⑼ 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;
}
}
⑽ 二維數組 安卓版怎麼賦值
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[][]={
{"小王","小李","小張"},
{"小紅","小明","小花"},
{"小雨","小風","小平","小雷"},
{"小單"}
}
看上述例子。對於不同的行,其相應的列數是不同的。