Android ListView类+ArrayAdapter类简单演示
2015-12-22 00:00
519 查看
摘要: Android ListView+ArrayAdapter简单演示。
其他的不说了,直接上代码:
MainActivity.java文件:
main.xml文件:
效果图:
代码很短,初学者很容易就看懂了,所以代码里就不加入注释了,我也不解说代码的作用了。
其他的不说了,直接上代码:
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>
效果图:
代码很短,初学者很容易就看懂了,所以代码里就不加入注释了,我也不解说代码的作用了。
相关文章推荐
- android,内容延伸到状态栏
- Android之实例界面设计
- Android之我的第一个程序
- Android之SQLite存取DATETIME类型
- Android 近百个项目的源代码
- Android之调用本地摄像头
- Android 中的BroadCastReceiver
- Android Service和Activity基于串口蓝牙模块的双向通信
- android 的NDK在Windwos环境搭建(一)
- android 公开静态内部类BroadcastReceiver
- Android之获取IP
- android 的Activity和Service之间的通信
- Android之控制视图
- android 的NDK在Windwos环境搭建(二)
- Android之handler的使用
- Android之在GEC210板上点灯。
- Android之Activity的生命周期
- android 在service中如何向activity传递数据
- Android-Data Storage
- 关于Android LayoutInflater