Arrays.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="country">
<item>신라</item>
<item>고구려</item>
<item>백제</item>
<item>당나라</item>
<item>발해</item>
<item>옥저</item>
<item>동예</item>
<item>부여</item>
<item>대한민국</item>
</string-array>
</resources>
Activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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/lv"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
MainActivity.java
package com.example.listviewex02;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<CharSequence> adapter
=ArrayAdapter.createFromResource(this, R.array.country, android.R.layout.simple_list_item_1);
ListView lv = (ListView)findViewById(R.id.lv);
lv.setAdapter(adapter);
lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lv.setDivider(new ColorDrawable(Color.YELLOW));
lv.setDividerHeight(5);
}
@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;
}
}
'Android' 카테고리의 다른 글
리스트뷰 - 항목 추가,삭제하기 (multiplechoice) (0) | 2013.04.01 |
---|---|
리스트뷰 - 항목 추가, 삭제하기(singlechoice) (0) | 2013.04.01 |
리스트뷰 - 어댑터뷰 (0) | 2013.03.29 |
메뉴 - context (0) | 2013.03.29 |
메뉴 - 체크메뉴 (0) | 2013.03.29 |