关闭

Android 基础-最简单的listView实现 ArrayAdapter

标签: androidxmlapkimageviewlistview
345人阅读 评论(0) 收藏 举报
分类:
/**
 * 
 * @author Administrator
 *ListView
 *适配器——1.设置ListView条目数量
 * 2.控制每个条目现实的内容
 */
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView list=(ListView)findViewById(R.id.list);
String[]data={"小王","大王","小王他哥","老王","隔壁老王","小黑","拍拍","剃刀"};
ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,data);
list.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}


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"  android:paddingBottom="@dimen/activity_vertical_margin"
   android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
   android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
   <ListView 
       android:id="@+id/list"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent"
       ></ListView>
</RelativeLayout>


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:27075次
    • 积分:668
    • 等级:
    • 排名:千里之外
    • 原创:45篇
    • 转载:0篇
    • 译文:0篇
    • 评论:1条