欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ListView下拉列表控件使用方法詳解

 更新時(shí)間:2022年08月26日 08:54:07   作者:linkinparkzlz  
這篇文章主要為大家詳細(xì)介紹了ListView下拉列表控件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了ListView下拉列表控件的使用方法,供大家參考,具體內(nèi)容如下

ListView列表控件

列表的顯示需要三個(gè)元素:

view 用來顯示數(shù)據(jù)的view
適配器 用來把數(shù)據(jù)映射到view的中介
數(shù)據(jù) 具體的將被映射的字符串,圖片,或者基本組件

案例代碼

布局文件代碼

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
? ? android:layout_width="fill_parent"
? ? android:layout_height="fill_parent"
? ? ?>

? ? <ListView?
? ? ? ? android:id="@+id/lv_list"
? ? ?android:layout_width="match_parent"
? ? ?android:layout_height="match_parent"
? ? ? ? />


</LinearLayout>

activity代碼

package rr.yy;

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 ListViewDemo extends Activity {
? ?private ListView lv_list;
? ? @Override?
? ? public void onCreate(Bundle savedInstanceState) {
? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? setContentView(R.layout.main);
? ? ? ? lv_list=(ListView)findViewById(R.id.lv_list);
? ? ? ? final ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData());
? ? ? ? lv_list.setAdapter(adapter);
? ? ? ? lv_list.setOnItemClickListener(new OnItemClickListener() {

? ? ? ? ? ? @Override
? ? ? ? ? ? public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
? ? ? ? ? ? ? ? ? ? long arg3) {
? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? String txt =adapter.getItem(arg2);
? ? ? ? ? ? ? ? Toast.makeText(ListViewDemo.this, txt, 0).show();
? ? ? ? ? ? }
? ? ? ? });

? ? } ??
? ? private String[] getData() {
? ? ? ? // TODO Auto-generated method stub
? ? ? ? return new String[]{"lin","kin","park","好好","先生","上學(xué)","但是","得分","讀書","克扣","奮斗"};
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論