Android常用控件:ListView

来源:互联网 发布:知乎用户童谣 编辑:程序博客网 时间:2024/05/18 01:00

ListView的简易实现

效果图:


布局文件:activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.csdn.MainActivity" >    <ListView        android:id="@+id/listview"        android:layout_width="match_parent"        android:layout_height="match_parent" /></RelativeLayout>

JAVA文件:MainActivity.java

package com.example.csdn;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;public class MainActivity extends Activity {private ListView listview;private String[] listItem;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findBYId();setListView();}private void findBYId() {listview = (ListView) findViewById(R.id.listview);}private void setListView() {listItem = new String[] { "1", "1", "1", "1", "1", "1", "1", "1", "1","1", "1", "1", "1" };listview.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1, listItem));}}



0 0
原创粉丝点击