zoukankan      html  css  js  c++  java
  • ListView实现简单列表

    ListView实现简单列表

    效果图:

    啥也没干的ListView张这样:

    fry.Activity01

     1 package fry;
     2 
     3 import com.example.ListView.R;
     4 
     5 import android.app.Activity;
     6 import android.os.Bundle;
     7 import android.view.View;
     8 import android.widget.AdapterView;
     9 import android.widget.AdapterView.OnItemClickListener;
    10 import android.widget.ArrayAdapter;
    11 import android.widget.ListView;
    12 import android.widget.Toast;
    13 
    14 public class Activity01 extends Activity implements OnItemClickListener{
    15     private ListView listView;
    16     @Override
    17     protected void onCreate(Bundle savedInstanceState) {
    18         // TODO Auto-generated method stub
    19         super.onCreate(savedInstanceState);
    20         setContentView(R.layout.activity01);
    21         listView=(ListView) findViewById(R.id.listView);
    22         ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, getData());
    23         listView.setAdapter(adapter);
    24         listView.setOnItemClickListener(this);
    25     }
    26     @Override
    27     public void onItemClick(AdapterView<?> parent, View view, int position,
    28             long id) {
    29         // TODO Auto-generated method stub
    30         String string=(String) parent.getItemAtPosition(position);
    31         
    32         Toast.makeText(this, string, Toast.LENGTH_SHORT).show();
    33     }
    34     
    35     private String[] getData(){
    36         return new String[]{"韩寒","蔡静","卢本伟","五五开","战狼2","朝阳兄","虹桥一姐","犀利哥","王宝庆",
    37                 "系大大","搞踹踹","张三","李四","王五"};
    38     }
    39 }

    /ListView/res/layout/activity01.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:orientation="vertical" >
     6 
     7     <ListView 
     8         android:id="@+id/listView"
     9         android:layout_width="match_parent"
    10         android:layout_height="wrap_content"
    11         ></ListView>
    12 
    13 </LinearLayout>
  • 相关阅读:
    文件操作:根据现有类生成所需要的类
    Microsoft JScript 运行时错误: “”未定义
    未完成
    WPF模拟雷达界面效果图
    WebClient模拟网页提交表单
    201319
    Delphi中的InStrRev函数(倒找文本)
    利用IDhttp实现图片下载
    白话解释哈希表
    整理的Delphi常用字符串函数
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/7409227.html
Copyright © 2011-2022 走看看