編輯:關於Android編程
學習android三天了,發現這個ListView在android裡應用非常的多,於是就花了一些時間仔細學習了一下!
以下是我個人的理解,如果有錯誤或不周到的地方,還請各位看客留言!有錯誤才有進步,這是我的名言!!!呵呵!
簡單的介紹以下,ListVeiw就像一個對象集合,可以將數據一列一列的顯示出來,而且可以添加點擊事件,非常方便用戶操作
手機自帶的系統用的比較多
比如手機的設置界面:
*布局設計<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+1eLR+bXEvefD5tDo0qrBvbj2TGF5b3V01sbX96Os0ru49r7NysdNYWluTGF5b3V0o6zA78PmsPy6rNK7uPZMaXN0VmlldzwvcD4KPHA+tPrC68jnz8KjujwvcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">
下面是PerListViewLayout,裡面是每一條數據的樣式
代碼如下:
對應的界面如下:
大概可以分成這幾個部分:
這個可以成為每一列數據的樣式與布沮喎?/kf/yidong/wp/" target="_blank" class="keylink">WPC9wPgo8cD7S1LrzTWFpbkxheW91dMDvw+a1xMO/zPXK/b7dtry74dLU1eLR+bXEt73Kvc/Uyr6z9sC0PC9wPgo8cD4qIMr9vt3UtLXEtLS9qDxicj4KytfPyNKqyKGz9sr9vt2jrLyw0qrP1Mq+vLjM9cr9vt08L3A+CjxwPrSpvP7I/bj2yv3X6aOst9ax8LTmyOtpbWFnZVZpZXehonRleHRWaWV3MaGidGV4dFZpZXcyPC9wPgo8cD60+sLryOfPwqO6PC9wPgo8cD48L3A+CjxwcmUgY2xhc3M9"brush:java;">private int[] picts = {R.drawable.ic_launcher, R.drawable.pict1, R.drawable.pict2, R.drawable.dog_bew}; private String[] contents1 = {"zhangsan", "lisi", "wangwu", "wangliu"}; private String[] contents2 = {"zhangsan_1", "lisi_1", "wangwu_1", "wangliu_1"};圖片資源的id,textView1的內容,textView2的內容。一一對應
將數據存入List裡
代碼如下:
// 創建數據源 List
開始創建自定義適配器
代碼如下:
class MyAdapter extends SimpleAdapter { public MyAdapter(Context context, List extends Map注意上面的view,事件是點擊MainLayout獲取PerListViewLayout裡的各個控件的id和文本> data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); } @Override public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); ImageView imageview = (ImageView)view.findViewById(R.id.imageViewId); TextView textview1 = (TextView)view.findViewById(R.id.textviewId1); TextView textview2 = (TextView)view.findViewById(R.id.textviewId2); imageview.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Toast.makeText(ListViewActivity3.this, "點擊的是圖片", Toast.LENGTH_SHORT).show(); } }); textview1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Toast.makeText(ListViewActivity3.this, "點擊的是文字1", Toast.LENGTH_SHORT).show(); } }); textview2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { Toast.makeText(ListViewActivity3.this, "點擊的是文字2", Toast.LENGTH_SHORT).show(); } }); // 實現事件。。。 return view; } }
代碼如下:
// 創建適配器 MyAdapter adapter = new MyAdapter(ListViewActivity3.this, data, R.layout.listview_one_linex, from, to); listview.setAdapter(adapter); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView> arg0, View arg1, int position, long arg3) { Toast.makeText(ListViewActivity3.this, "第"+ (position+1) + "行", Toast.LENGTH_SHORT).show(); } });開始看看from和to參數,
context - The context where the View associated with this SimpleAdapter is running data - A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entri es specified in "from" resource - Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defin ed in "to" from - A list of column names that will be added to the Map associated with each item. to - The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of t he first N columns in the from parameter.英文看不懂,自己看吧,我的理解就是 一一對應關系
private String[] from = {"pict","contents1","contents2"}; private int[] to = {R.id.imageViewId, R.id.textviewId1, R.id.textviewId2};
代碼運行起來的結果
下面是我做的圖
這個是我自己的理解,肯定有很多地方不合理,我自己是懂了!!!!
Android Studio 打包及引用 aar1、 簡述在比較大的 Android 項目的開發中,我們經常會遇到工程、jar 包等等之間相互引用的方式。一般我們通過在
Service是什麼 它是android App的四大組件之一,在開發中我們有時需要做一些耗時的但不需要與用戶建立界面交互的操作可以考慮使用service。比如:比如我
Device Administration對於這個應用,市場上很多,但是看一下評論就知道效果有多差了,因為99%一鍵鎖屏應用沒辦法卸載。今天就開發一個小應用,實現輕松點擊
基於淺談 Google Skia 圖形處理引擎和Skia Demo Build。 Skia是一個跨平台的圖形庫,目前使用在Android中,同樣也有PC版本,這裡測試一下