日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用ListView顯示數(shù)據(jù)

效果圖

創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設,疊彩企業(yè)網(wǎng)站建設,疊彩品牌網(wǎng)站建設,網(wǎng)站定制,疊彩網(wǎng)站建設報價,網(wǎng)絡營銷,網(wǎng)絡優(yōu)化,疊彩網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。

1、先定義item

 
 
 
 
  1.  
  2.  xmlns:Android="http://schemas.android.com/apk/res/android"   
  3.     android:orientation="horizontal"   
  4.     android:layout_width="fill_parent"   
  5.     android:layout_height="wrap_content"> 
  6.  
  7.    android:layout_width="80dip"   
  8.    android:layout_height="wrap_content" 
  9.    android:id="@+id/personid" 
  10.  />   
  11.  
  12.    android:layout_width="100dip" 
  13.    android:layout_height="wrap_content" 
  14.    android:id="@+id/name"   
  15. />    
  16.  
  17.    android:layout_width="fill_parent"   
  18.    android:layout_height="wrap_content"   
  19.    android:id="@+id/amount"   
  20.  /> 
  21.  

2、通過適配器把數(shù)據(jù)綁定到ListView中,點擊某一行數(shù)據(jù)顯示編號

方式一:

 
 
 
 
  1. List> data=new ArrayList>();   
  2.        for(Person person :persons){   
  3.          HashMap hashMap=new HashMap();  
  4.          hashMap.put("id", person.getPersonId());  
  5.          hashMap.put("name", person.getName());  
  6.          hashMap.put("amount", person.getAmount());   
  7.          data.add(hashMap);  
  8.  }   
  9. SimpleAdapter adapter=new SimpleAdapter(this,data,R.layout.item,new String[]{"id","name","amount"},new int[]{R.id.personid,R.id.name,R.id.amount});              listView.setAdapter(adapter);  
  10.  listView.setOnItemClickListener(new OnItemClickListener(){   
  11. @Override  
  12. public void onItemClick(AdapterView parent, View view,  
  13.    int position, long id) {   
  14.    ListView myListView=(ListView)parent;  
  15.    HashMap item=(HashMap)myListView.getItemAtPosition(position);  
  16.    Toast.makeText(DBActivity.this, item.get("id").toString() , Toast.LENGTH_SHORT).show();  
  17.     }  
  18.   }   
  19. ); 

方式二:用游標的方式

 
 
 
 
  1. Cursor cursor=personService.getCursor(0, 15);        //要求字段中要有_id  設計表的時候的主鍵為_id          
  2. SimpleCursorAdapter cursorAdapter=new SimpleCursorAdapter(this,R.layout.item,cursor,new String[]{"_id","name","amount"},new   int[]{R.id.personid,R.id.name,R.id.amount});    
  3. listView.setAdapter(cursorAdapter);    
  4. listView.setOnItemClickListener(new OnItemClickListener(){   
  5. /**   
  6.  * parent當前所點擊的listview對象   
  7.  * view當前所點擊的條目   
  8. */   
  9. @Override   
  10.  public void onItemClick(AdapterView parent, View view,  
  11.    int position, long id) {   
  12.    ListView myListView=(ListView)parent;  
  13.    Cursor data=(Cursor)myListView.getItemAtPosition(position);//根據(jù)位置移動游標  
  14.    int m=data.getInt(data.getColumnIndex("_id"));   
  15.    Toast.makeText(DBActivity.this, String.valueOf(m) , Toast.LENGTH_SHORT).show();  
  16.     }  
  17.   }  
  18. ); 

 【編輯推薦】

Android智能手機操作系統(tǒng)

SQL Server與Oracle數(shù)據(jù)庫鏡像對比

在Android應用程序中使用Internet數(shù)據(jù)

在不同字符集的數(shù)據(jù)庫之間導入數(shù)據(jù)的方法


網(wǎng)站欄目:使用ListView顯示數(shù)據(jù)
URL分享:http://www.5511xx.com/article/coiphoc.html