ListView如何實(shí)現(xiàn)簡單列表,供大家參考,具體內(nèi)容如下
創(chuàng)新互聯(lián)公司主要從事網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)貴定,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18980820575
效果圖:
啥也沒干的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); ArrayAdapteradapter=new ArrayAdapter (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[]{"韓寒","蔡靜","盧本偉","五五開","戰(zhàn)狼2","朝陽兄","虹橋一姐","犀利哥","王寶慶", "系大大","搞踹踹","張三","李四","王五"}; } }
/ListView/res/layout/activity01.xml
<?xml version="1.0" encoding="utf-8"?>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。