결과화면

package com.example.containerdemo;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewDemo2 extends ListActivity {
 String[] items = null;
 private TextView selected;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.listviewdemo_2);

  selected = (TextView)findViewById(R.id.selected);

  items = getResources().getStringArray(R.array.phone);


  setListAdapter(new ArrayAdapter<String>
  (this, android.R.layout.simple_list_item_1, items));

 

//  setListAdapter(new ArrayAdapter<String>
//  (this, android.R.layout.simple_list_item_single_choice, items));
//  
//  setListAdapter(new ArrayAdapter<String>
//  (this, android.R.layout.simple_list_item_multiple_choice, items));
 }


 public void onListItemClick(ListView parent, View v, int position, long id){
  selected.setText(items[position] + " : " + position + ":" + id);
 }
}

 

 

 

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="선택항목 : " />

        <TextView
            android:id="@+id/selected"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="선택한 것이 없습니다." />
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

 

 

 

 

 

//values폴더에 arrays.xml 생성

 

 

 <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="phone">
        <item>Iphone4</item>
        <item>Iphone4s</item>
        <item>Iphone5</item>
        <item>Iphone5s</item>
        <item>Iphone5c</item>
        <item>galaxy S</item>
        <item>galaxy S2</item>
        <item>galaxy S2 HD</item>
        <item>galaxy S3 3G</item>
        <item>galaxy S3 LTE</item>
        <item>galaxy S4</item>
        <item>galaxy S4 LTE-A</item>
        <item>vega R3</item>
        <item>vega IRON</item>
        <item>vega LTE-A</item>
        <item>optimus G</item>
        <item>optimus G PRO</item>
        <item>optimus GK</item>
        <item>G2</item>
    </string-array>
</resources>

 

'2020년도 이전 > [WebSig] Android' 카테고리의 다른 글

ListView Demo5  (0) 2013.08.14
ListView Demo3 - 리스트 추가, 삭제  (0) 2013.08.14
ListView Demo1  (0) 2013.08.14
HScrollView Demo  (0) 2013.08.14
SeekBar Demo  (0) 2013.08.13

+ Recent posts