ListView实现简单列表_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > ListView实现简单列表

ListView实现简单列表

 2017/8/22 10:08:47  钻石VIP  程序员俱乐部  我要评论(0)
  • 摘要:ListView实现简单列表效果图:啥也没干的ListView张这样:fry.Activity011packagefry;23importcom.example.ListView.R;45importandroid.app.Activity;6importandroid.os.Bundle;7importandroid.view.View;8importandroid.widget.AdapterView;9importandroid.widget.AdapterView
  • 标签:实现 view list

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>

 

发表评论
用户名: 匿名