●畫面預覽:
●補充說明:
(一)Adapter=> 把資料和listview結合
An Adapter object acts as a bridge between an
AdapterView
and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View
for each item in the data set.(二)序列化:把資料儲存到物件
(三)Arraylist自己就可以直接序列化儲存
.png)

(四)ArrayAdapter:是android內建的adapter,有內建的layout可以用,不需要另外自己寫layout
=>不能用2維陣列,只能用1維陣列和arraylist
●程式與說明--java code
lv = (ListView) findViewById(R.id.lv);
adp=new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, ar);
registerForContextMenu(lv);
lv.setAdapter(adp);
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick
(AdapterView<?> adapterView, View view, int i, long l) {
index=i;
//如果定return true就不會跳出contextmenu
//true if the callback consumed the long click, false otherwise
return false;
}
});
**說明:
1.先建立一個陣列
2.直接new ArrayAdapter,給三個參數,第一個是context,第二個是layout的樣子,第三個是要放進去的資料陣列
3.把listView設定給ArrayAdapter
●程式參考(GitHub):檔案存取(二)Adapter與ListView
文章標籤
全站熱搜