編輯:關於Android編程
通常在使用自定義適配器的時候,我們都會掌握一種固定的模式。充分利用convertView+緩存的方式。
private ArrayList最近,做百度地圖離線下載的時候,發現一種新的方式,很想知道百度的android程序員是如何來寫代碼的。仔細一看,確實有很大不同。list ; private LayoutInflater mInflater; public DetailListAdapter(Context context,ArrayList list){ this.list=list; mInflater = LayoutInflater.from(context); } @Override public int getCount() { // TODO Auto-generated method stub return list == null ?0:list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if(convertView == null){ convertView = mInflater.inflate(R.layout.search_info_item_layout, null); holder = new ViewHolder(); holder.TimeTxt = (TextView) convertView.findViewById(R.id.time_tv); holder.AddressTxt = (TextView) convertView.findViewById(R.id._address_tv); holder.processFlagTxt = (TextView) convertView.findViewById(R.id.process_flag_tv); convertView.setTag(holder); }else{ holder = (ViewHolder) convertView.getTag(); } holder.TimeTxt.setText(list.get(position).getTime()); holder.AddressTxt.setText(list.get(position).getAddress()); holder.processFlagTxt.setText(list.get(position).getState()); return convertView; } class ViewHolder{ TextView TimeTxt; TextView AddressTxt; TextView processFlagTxt; } }
來自百度地圖離線下載的Demo
private ArrayListlocalMapList = null; public class LocalMapAdapter extends BaseAdapter { @Override public int getCount() { return localMapList.size(); } @Override public Object getItem(int index) { return localMapList.get(index); } @Override public long getItemId(int index) { return index; } @Override public View getView(int index, View view, ViewGroup arg2) { MKOLUpdateElement e = (MKOLUpdateElement) getItem(index); view = View.inflate(OfflineDemo.this, R.layout.offline_localmap_list, null); initViewItem(view, e); return view; } void initViewItem(View view, final MKOLUpdateElement e) { Button display = (Button) view.findViewById(R.id.display); Button remove = (Button) view.findViewById(R.id.remove); TextView title = (TextView) view.findViewById(R.id.title); TextView update = (TextView) view.findViewById(R.id.update); TextView ratio = (TextView) view.findViewById(R.id.ratio); ratio.setText(e.ratio + "%"); title.setText(e.cityName); if (e.update) { update.setText("可更新"); } else { update.setText("最新"); } if (e.ratio != 100) { display.setEnabled(false); } else { display.setEnabled(true); } remove.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { mOffline.remove(e.cityID); updateView(); } }); display.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("x", e.geoPt.longitude); intent.putExtra("y", e.geoPt.latitude); intent.setClass(OfflineDemo.this, BaseMapDemo.class); startActivity(intent); } }); } }
Android-ListView兩種適配器ListView在安卓App中非常常見,幾乎每一個App都會有涉及,比如QQ消息列表,或者是通訊錄還有就是酷我音樂的歌曲列表都是
現在app中,圖片預覽功能肯定是少不了的,用戶基本已經形成條件反射,看到小圖,點擊看大圖,看到大圖兩個手指開始進行放大,放大後,開始移動到指定部位。一、概述想要做到圖片支
andriod短信整合備份發送到gmail郵箱,需要在andoid手機配置好gmail郵箱 github代碼 https://github.com/zhwj184/sms
前提本教程默認以下幾點你已經完全滿足:開通了認證後的服務號 服務號開通的微信支付的認證 騰訊給你的郵件中有商戶登錄的賬號和密碼 擁有一個可供上傳代碼和設置回調域名的網站或