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

Android ListView类+ArrayAdapter类简单演示

2015-12-22 00:00 519 查看
摘要: Android ListView+ArrayAdapter简单演示。

其他的不说了,直接上代码:

MainActivity.java文件:

package com.example.yaowen.testapp;

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

public class MainActivity extends AppCompatActivity {

private ListView listView;
private String[] lists;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView= (ListView) findViewById(R.id.lv);
lists= new String[]{
"YUWEN","SHUXUE","DILI"
};
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,lists);
listView.setAdapter(adapter);
}
}

main.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<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.yaowen.testapp.MainActivity">

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

效果图:



代码很短,初学者很容易就看懂了,所以代码里就不加入注释了,我也不解说代码的作用了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: