您的位置:首页 > 移动开发 > Android开发

Android重要控件———ListView

2016-02-29 21:16 513 查看
<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" >

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

</ListView>
</RelativeLayout>


package com.example.listviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListviewtestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewtest);

ListView lv =(ListView)findViewById(R.id.list_view);
String[] data ={"apple","banana","watermelon","pear","peach","grape","mango","strawberry","tomato","pineapple","cherry","tea","coin","hha"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(ListviewtestActivity.this,android.R.layout.simple_list_item_1,data);
lv.setAdapter(adapter);

}
}





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: