Focus on technology, enjoy life!—— QQ:804212028
浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305
ListView的ArrayAdapter适配显示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
MainActivity.java源代码:
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
private ListView listView;
String[] str={"aa","bb","cc","dd","ee"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.listView);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str);
listView.setAdapter(adapter);
}
}
运行结果:
今天有点晚了。。明天我会继续更新,还很多知识点。
步步为营系列课程,会不断地反复编辑,去掉一些之前没写好的,增加新的好的东西。所以这个系列的博客文章会一直越来越好,越来越全面。大家支持的话,请关注这个系列。
Focus on technology, enjoy life!—— QQ:804212028
浏览链接:http://blog.csdn.net/y18334702058/article/details/44624305
步步为营_Android开发课[19]_用户界面之ListView(列表视图)
原文地址:http://blog.csdn.net/y18334702058/article/details/44948011