



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】android中l(wèi)istview怎么用
MainActivitypackage
com.example1.listviewpracticvce;
/*
*
本例子實(shí)現(xiàn)的功能:
*
用listview顯示給定的一個(gè)靜態(tài)數(shù)組,數(shù)組定義在string.xml中攻或者activity中
*/
import
.sip.SipAudioCall.Listener;
import
android.os.Bundle;
import
android.app.ListActivity;
import
android.view.View;
import
android.widget.AdapterView;
import
android.widget.AdapterView.OnItemClickListener;
import
android.widget.ArrayAdapter;
import
android.widget.ListView;
import
android.widget.TextView;
import
android.widget.Toast;
public
class
MainActivity
extends
ListActivity
{//也可以用activity
//static
final
String[]
CONTENT={"china","america","russia","japan"};
//
String[]
countries
=
getResources().getStringArray(R.array.countries_array);
//
數(shù)據(jù)類型是不能放在public里的,必須話oncreate里面!!
@Override
protected
void
onCreate(Bundle
savedInstanceState)
{
String[]
countries
=
getResources().getStringArray(R.array.countries_array);
//
setContentView(R.layout.main);
extends
ListActivity后就注意這里不用這條語(yǔ)句
super.onCreate(savedInstanceState);
//這種方法將數(shù)組存放在values/string.xml里面,顯得不亂,但是如果數(shù)據(jù)來(lái)源于網(wǎng)絡(luò)就不好了
//
setListAdapter(new
ArrayAdapter<String>(this,
R.layout.list_item,
COUNTRIES));
//adapter有好幾種,處理數(shù)據(jù)庫(kù)用cursoradapter
//只有activity
extends
listactivity才能用setListAdapter
setListAdapter(new
ArrayAdapter<String>(this,
R.layout.list_item,countries));
//
綁定數(shù)組
context
每一行顯示的布局
數(shù)組文件
//setListAdapter(new
ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,CONTENT));
ListView
lV
=
getListView();
//當(dāng)你遵循了listview的這些規(guī)則后,用這條語(yǔ)句就能自動(dòng)獲取listview
//listview的規(guī)則有:
//(1)activity
extends
listactivity(不必須)
//(2)view必須包含五個(gè)listview對(duì)象,并且id這樣命名:"","@id/android:list",當(dāng)沒(méi)有l(wèi)istview的內(nèi)容時(shí)可以用"@id/android:empty"來(lái)顯示其它信息
//(3)當(dāng)listview比較簡(jiǎn)單時(shí)可以不用自己定義list_item,它給我們提供了一個(gè)定義好的:android.R.layout.simple_list_item_1只有遵循了(2)才行
lV.setTextFilterEnabled(true);
//點(diǎn)擊事件最好直接copy,我試了下寫new
listener居然是不能顯示的
lV.setOnItemClickListener(new
OnItemClickListener()
{
public
void
onItemClick(AdapterView<?>
parent,
View
view,
int
position,long
id)
{
Toast.makeText(getApplicationContext(),
((TextView)view).getText(),
Toast.LENGTH_SHORT).show();
}
});
}
}<RelativeLayout
xmlns:android="/apk/res/android"
xmlns:tools="/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
>
<TextView
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
/>
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout><?xml
version="1.0"
encoding="utf-8"?>
<TextView
xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
>
</TextView><?xml
version="1.0"
encoding="utf-8"?>
<resources>
<string
name="app_name">28.ListViewPracticvce</string>
<string
name="action_settings">Settings</string>
<string
name="hello_world">Hello
world!</string>
<string-array
name="countries_array">
<item>Bahrain</item>
<item>Bangladesh</item>
<item>Barbad
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 合同模板下載指南
- 家用折疊健身車行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 阻燃劑企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級(jí)戰(zhàn)略研究報(bào)告
- 二零二五年度暗股投資創(chuàng)業(yè)項(xiàng)目合作協(xié)議
- 彩花雨鞋企業(yè)ESG實(shí)踐與創(chuàng)新戰(zhàn)略研究報(bào)告
- 工藝品拖鞋企業(yè)數(shù)字化轉(zhuǎn)型與智慧升級(jí)戰(zhàn)略研究報(bào)告
- 天然藥物原料藥行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 防凍液企業(yè)ESG實(shí)踐與創(chuàng)新戰(zhàn)略研究報(bào)告
- 2025年度汽車美容店員工勞動(dòng)合同解除及補(bǔ)償合同樣本
- 仿制抗血栓藥行業(yè)跨境出海戰(zhàn)略研究報(bào)告
- 四川省既有居住小區(qū)改造技術(shù)標(biāo)準(zhǔn)
- 慢性血栓栓塞性肺動(dòng)脈高壓診斷與治療指南(2024版)解讀
- 2024年南京科技職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)完整
- 小學(xué)生國(guó)家文化安全教育
- 2024年常州工業(yè)職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)及答案解析
- AQ-T 3002-2021阻隔防爆橇裝式加油(氣)裝置技術(shù)要求
- 綠植租擺投標(biāo)方案
- 新聞編輯學(xué)PDF蔡雯第四版
- 行政處罰自由裁量權(quán)課件
- Unit-3-Reading-and-thinking課文詳解課件-高中英語(yǔ)人教版必修第二冊(cè)
- 肝病科進(jìn)修總結(jié)匯報(bào)
評(píng)論
0/150
提交評(píng)論