결과화면

 

 package com.example.containerdemo;

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

public class ListViewDemo1 extends Activity {
 String[] items = null;
 private TextView selected;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.listviewdemo_1);
  
  selected = (TextView)findViewById(R.id.selected);
  ListView listview = (ListView)findViewById(R.id.list);
  
  items = getResources().getStringArray(R.array.phone);
  listview.setAdapter(new ArrayAdapter<String>
  (this, android.R.layout.simple_list_item_1, items));
  
  listview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
   public void onItemClick(AdapterView<?> 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="match_parent"
        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="@+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 Demo3 - 리스트 추가, 삭제  (0) 2013.08.14
ListView Demo2 - extends ListActivity 이용...  (0) 2013.08.14
HScrollView Demo  (0) 2013.08.14
SeekBar Demo  (0) 2013.08.13
ProgressBar Demo3  (0) 2013.08.13

+ Recent posts