Android ListView實(shí)現(xiàn)簡(jiǎn)單列表功能
ListView如何實(shí)現(xiàn)簡(jiǎn)單列表,供大家參考,具體內(nèi)容如下

效果圖:


啥也沒(méi)干的ListView張這樣:

fry.Activity01
package fry;
import com.example.ListView.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class Activity01 extends Activity implements OnItemClickListener{
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity01);
listView=(ListView) findViewById(R.id.listView);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, getData());
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
String string=(String) parent.getItemAtPosition(position);
Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
}
private String[] getData(){
return new String[]{"韓寒","蔡靜","盧本偉","五五開(kāi)","戰(zhàn)狼2","朝陽(yáng)兄","虹橋一姐","犀利哥","王寶慶",
"系大大","搞踹踹","張三","李四","王五"};
}
}
/ListView/res/layout/activity01.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" ></ListView> </LinearLayout>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android開(kāi)發(fā)中怎樣調(diào)用系統(tǒng)Email發(fā)送郵件(多種調(diào)用方式)
在Android中調(diào)用其他程序進(jìn)行相關(guān)處理,幾乎都是使用的Intent,所以,Email也不例外,所謂的調(diào)用Email,只是說(shuō)Email可以接收Intent并做這些事情2013-06-06
Android開(kāi)發(fā)之動(dòng)畫實(shí)現(xiàn)方法
這篇文章主要介紹了Android開(kāi)發(fā)之動(dòng)畫實(shí)現(xiàn)方法,實(shí)例分析了Android中動(dòng)畫的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-05-05
詳解Android系統(tǒng)啟動(dòng)過(guò)程
這篇文章主要介紹了Android系統(tǒng)啟動(dòng)過(guò)程的相關(guān)資料,幫助大家更好得理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下2021-03-03
Android中TabLayout+ViewPager實(shí)現(xiàn)tab和頁(yè)面聯(lián)動(dòng)效果
本篇文章主要介紹了Android中TabLayout+ViewPager實(shí)現(xiàn)tab和頁(yè)面聯(lián)動(dòng)效果,具有一定的參考價(jià)值,有興趣的可以了解一下2017-06-06
不允許錯(cuò)過(guò)的Anndroid技術(shù)經(jīng)驗(yàn)60條
不允許錯(cuò)過(guò)的Anndroid技術(shù)經(jīng)驗(yàn)60條,與大家分享,希望可以提高大家Android開(kāi)發(fā)水平,感興趣的朋友可以參考一下2016-02-02
Kotlin作用域函數(shù)應(yīng)用詳細(xì)介紹
作用域函數(shù):是Kotlin標(biāo)準(zhǔn)庫(kù)中的內(nèi)聯(lián)函數(shù),作用在對(duì)象上時(shí),執(zhí)行給定的block代碼塊??梢栽赽lock代碼塊中通過(guò)it,this代表當(dāng)前對(duì)象,進(jìn)行代碼邏輯處理2022-08-08

