(1) 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"
tools:context=".MainActivity" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
(2) item1.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="25sp"
android:background="#000000"
android:layout_margin="3dp"
android:text="aaa">
</TextView>
(3)MainActivity.java
package com.example.test12_listview;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.widget.ArrayAdapter;
public class MainActivity extends ListActivity {
ArrayList<String> arr=new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arr.add("봄");
arr.add("여름");
arr.add("가을");
arr.add("겨울");
ArrayAdapter<String> adapter=
new ArrayAdapter<String>(this,
R.layout.item1, //사용자가 만든 뷰를 항목뷰로 설정하기
arr);
setListAdapter(adapter);
}
}
'Mobile > Android' 카테고리의 다른 글
#15 ( spinner ) (0) | 2013.02.02 |
---|---|
#14 (ListView : layout파일 붙이고, 이벤트 주기 ) (0) | 2013.02.02 |
#12 (ListView: ListActivity 를 상속받아 처리하기 ) (0) | 2013.02.02 |
#11 (ListView : EditText에 값을 ListView에 추가하기 ) (0) | 2013.02.02 |
#10 ( ListView :리스트뷰와 데이터(모델)을 어댑터뷰(모델+레이아웃)를 이용해서 연결하기) (0) | 2013.02.02 |