新聞中心
效果圖

創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),疊彩企業(yè)網(wǎng)站建設(shè),疊彩品牌網(wǎng)站建設(shè),網(wǎng)站定制,疊彩網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,疊彩網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
1、先定義item
- xmlns:Android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- android:layout_width="80dip"
- android:layout_height="wrap_content"
- android:id="@+id/personid"
- />
- android:layout_width="100dip"
- android:layout_height="wrap_content"
- android:id="@+id/name"
- />
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/amount"
- />
2、通過適配器把數(shù)據(jù)綁定到ListView中,點(diǎn)擊某一行數(shù)據(jù)顯示編號
方式一:
- List
> data=new ArrayList >(); - for(Person person :persons){
- HashMap
hashMap=new HashMap (); - hashMap.put("id", person.getPersonId());
- hashMap.put("name", person.getName());
- hashMap.put("amount", person.getAmount());
- data.add(hashMap);
- }
- 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);
- listView.setOnItemClickListener(new OnItemClickListener(){
- @Override
- public void onItemClick(AdapterView> parent, View view,
- int position, long id) {
- ListView myListView=(ListView)parent;
- HashMap
item=(HashMap )myListView.getItemAtPosition(position); - Toast.makeText(DBActivity.this, item.get("id").toString() , Toast.LENGTH_SHORT).show();
- }
- }
- );
方式二:用游標(biāo)的方式
- Cursor cursor=personService.getCursor(0, 15); //要求字段中要有_id 設(shè)計(jì)表的時(shí)候的主鍵為_id
- 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});
- listView.setAdapter(cursorAdapter);
- listView.setOnItemClickListener(new OnItemClickListener(){
- /**
- * parent當(dāng)前所點(diǎn)擊的listview對象
- * view當(dāng)前所點(diǎn)擊的條目
- */
- @Override
- public void onItemClick(AdapterView> parent, View view,
- int position, long id) {
- ListView myListView=(ListView)parent;
- Cursor data=(Cursor)myListView.getItemAtPosition(position);//根據(jù)位置移動游標(biāo)
- int m=data.getInt(data.getColumnIndex("_id"));
- Toast.makeText(DBActivity.this, String.valueOf(m) , Toast.LENGTH_SHORT).show();
- }
- }
- );
【編輯推薦】
Android智能手機(jī)操作系統(tǒng)
SQL Server與Oracle數(shù)據(jù)庫鏡像對比
在Android應(yīng)用程序中使用Internet數(shù)據(jù)
在不同字符集的數(shù)據(jù)庫之間導(dǎo)入數(shù)據(jù)的方法
當(dāng)前文章:使用ListView顯示數(shù)據(jù)
網(wǎng)頁鏈接:http://m.fisionsoft.com.cn/article/coiphoc.html


咨詢
建站咨詢
