결과화면 

 

package com.example.containerdemo;

import java.util.ArrayList;
import java.util.Arrays;

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

public class ListViewDemo3 extends Activity {
 Button add, delete;
 ListView listview;
 EditText item_name;
 ArrayAdapter<String> adapter;
 int deletePos = -1;;
 TextView message;
 ArrayList<String> alist;

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

  add = (Button)findViewById(R.id.add);
  message = (TextView)findViewById(R.id.message);
  delete = (Button)findViewById(R.id.delete);
  listview = (ListView)findViewById(R.id.listview1);
  item_name = (EditText)findViewById(R.id.item_name);

  alist = new ArrayList<String>();
  alist.addAll(Arrays.asList(getResources().getStringArray(R.array.phone)));

  adapter = new ArrayAdapter<String>
  (this, android.R.layout.simple_list_item_1, alist);

  listview.setAdapter(adapter);

  add.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    alist.add(0, item_name.getText().toString());
    adapter.notifyDataSetChanged();
   }
  });

  delete.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View v) {
    if(deletePos == -1){
     message.setText("삭제할 Item(항목)을 선택하세요.");
    } else {
     alist.remove(deletePos);
     adapter.notifyDataSetChanged();
     message.setText("");
    }
   }
  });

  listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    deletePos = position;
    message.setText(alist.get(position) + "를 삭제하시겠습니까?");
   }
  });
 }
}

 

 

 

 

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

    <TextView
        android:id="@+id/message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="ListView에 추가할 항목 : " />

    <EditText
        android:id="@+id/item_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/add"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="추가" />

    <Button
        android:id="@+id/delete"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="삭제" />

    <ListView
        android:id="@+id/listview1"
        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' 카테고리의 다른 글

ExpandableList ViewDemo  (0) 2013.08.14
ListView Demo5  (0) 2013.08.14
ListView Demo2 - extends ListActivity 이용...  (0) 2013.08.14
ListView Demo1  (0) 2013.08.14
HScrollView Demo  (0) 2013.08.14

결과화면

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

결과화면

 

 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

 결과화면

 

 

 package com.example.containerdemo;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class HScrollViewDemo extends Activity {

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

 <HorizontalScrollView 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" >

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

        <TextView
            android:layout_width="200dip"
            android:layout_height="match_parent"
            android:background="#0000ff"
            android:gravity="center"
            android:text="@string/hello_world" />

        <TextView
            android:layout_width="300dip"
            android:layout_height="match_parent"
            android:background="#00ff00"
            android:gravity="center"
            android:text="@string/hello_world" />

        <TextView
            android:layout_width="400dip"
            android:layout_height="match_parent"
            android:background="#ff0000"
            android:gravity="center"
            android:text="@string/hello_world" />
    </LinearLayout>

</HorizontalScrollView>

 

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

ListView Demo2 - extends ListActivity 이용...  (0) 2013.08.14
ListView Demo1  (0) 2013.08.14
SeekBar Demo  (0) 2013.08.13
ProgressBar Demo3  (0) 2013.08.13
ProgressBar Demo2 -> 원형 프로그레스 바  (0) 2013.08.13

 결과화면

 

package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

public class SeekBarDemo extends Activity implements SeekBar.OnSeekBarChangeListener{
 SeekBar mSeekBar;
 TextView mProgressText;
 TextView mTrackingText;
 
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.seekbar_demo);
  
  mSeekBar = (SeekBar)findViewById(R.id.seek);
  mSeekBar.setOnSeekBarChangeListener(this);
  mProgressText = (TextView)findViewById(R.id.progress);
  mTrackingText = (TextView)findViewById(R.id.tracking);
 }
 
 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch){
  mProgressText.setText(progress + " " + getString(R.string.seekbar_from_touch) + "=" + fromTouch);
 }
 
 public void onStartTrackingTouch(SeekBar seekBar){
  mTrackingText.setText(getString(R.string.seekbar_tracking_on));
 }
 
 public void onStopTrackingTouch(SeekBar seekBar){
  mTrackingText.setText(getString(R.string.seekbar_tracking_off));
 }

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <SeekBar
        android:id="@+id/seek"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />

    <TextView
        android:id="@+id/progress"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/tracking"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

//String.xml에 코드 추가~!~!

 

 <string name="seekbar_tracking_on">Tracking on</string>
    <string name="seekbar_tracking_off">Tracking off</string>
    <string name="seekbar_from_touch">from touch</string>

 

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

ListView Demo1  (0) 2013.08.14
HScrollView Demo  (0) 2013.08.14
ProgressBar Demo3  (0) 2013.08.13
ProgressBar Demo2 -> 원형 프로그레스 바  (0) 2013.08.13
ProgressBar Demo1  (0) 2013.08.13

 결과화면

 

 

package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class ProgressBarDemo3 extends Activity {
 private boolean mToggle = false;
 
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
  setContentView(R.layout.progress_3);
  setProgressBarIndeterminateVisibility(mToggle);
  
  Button button = (Button)findViewById(R.id.toggle);
  button.setOnClickListener(new Button.OnClickListener(){
   public void onClick(View v){
    mToggle = !mToggle;
    setProgressBarIndeterminateVisibility(mToggle);
   }
  });
 }
}

 

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button android:id="@+id/toggle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/progressbar_4_toggle" />

</LinearLayout>

//String.xml에 다음 코드 추가~~

 

 <string name="progressbar_4_toggle">Toggle Indeterminate</string>

 

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

HScrollView Demo  (0) 2013.08.14
SeekBar Demo  (0) 2013.08.13
ProgressBar Demo2 -> 원형 프로그레스 바  (0) 2013.08.13
ProgressBar Demo1  (0) 2013.08.13
Image Demo  (0) 2013.08.13

 결과화면

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.*;

public class ProgressBarDemo2 extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  requestWindowFeature(Window.FEATURE_PROGRESS);
  setProgressBarVisibility(true); //위에 requestWindowFeature 를 true로 지정한거임..
  
  setContentView(R.layout.progress_2);

 }
}

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ProgressBar android:id="@+android:id/progress_large"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar android:id="@+android:id/progress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar android:id="@+android:id/progress_small"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ProgressBar android:id="@+android:id/progress_small_title"
        style="?android:attr/progressBarStyleSmallTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

 

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

SeekBar Demo  (0) 2013.08.13
ProgressBar Demo3  (0) 2013.08.13
ProgressBar Demo1  (0) 2013.08.13
Image Demo  (0) 2013.08.13
AutoText Demo 자동완성 텍스트뷰  (0) 2013.08.13

 결과화면

 

 package com.example.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.*;

public class ProgressBarDemo1 extends Activity {
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  //윈도우에 진행 상태바 설정.
  requestWindowFeature(Window.FEATURE_PROGRESS);
  setProgressBarVisibility(true); //위에 requestWindowFeature 를 true로 지정한거임..
  
  setContentView(R.layout.progress_1);
  
  final ProgressBar progressHorizontal =
    (ProgressBar)findViewById(R.id.progress_horizontal);
  
  setProgress(progressHorizontal.getProgress() * 100);
  setSecondaryProgress(progressHorizontal.getSecondaryProgress() * 100);
  
  Button button = (Button)findViewById(R.id.increase);
  button.setOnClickListener(new Button.OnClickListener(){
   public void onClick(View v){
    progressHorizontal.incrementProgressBy(1);
    //Title progress is in range 0..10000
    setProgress(100 * progressHorizontal.getProgress());
   }
  });
  
  button = (Button)findViewById(R.id.decrease);
  button.setOnClickListener(new Button.OnClickListener(){
   public void onClick(View v){
    progressHorizontal.incrementProgressBy(-1);
    //Title progress is in range 0..10000
    setProgress(100 * progressHorizontal.getProgress());
   }
  });
  
  button = (Button)findViewById(R.id.increase_secondary);
  button.setOnClickListener(new Button.OnClickListener(){
   public void onClick(View v){
    progressHorizontal.incrementSecondaryProgressBy(1);
    //Title progress is in range 0..10000
    setProgress(100 * progressHorizontal.getProgress());
   }
  });
  
  button = (Button)findViewById(R.id.decrease_secondary);
  button.setOnClickListener(new Button.OnClickListener(){
   public void onClick(View v){
    progressHorizontal.incrementSecondaryProgressBy(-1);
    //Title progress is in range 0..10000
    setProgress(100 * progressHorizontal.getProgress());
   }
  });
 }
}

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ProgressBar android:id="@+id/progress_horizontal"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="200dip"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="50"
        android:secondaryProgress="75" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/progressbar_1_default_progress" />       

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

        <Button android:id="@+id/decrease"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/progressbar_1_minus" />

        <Button android:id="@+id/increase"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/progressbar_1_plus" />

    </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/progressbar_1_secondary_progress" />       

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

        <Button android:id="@+id/decrease_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/progressbar_1_minus" />

        <Button android:id="@+id/increase_secondary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/progressbar_1_plus" />

    </LinearLayout>

</LinearLayout>

//String.xml에 다음 코드 추가~~

 

 <string name="progressbar_1_plus">+</string>
    <string name="progressbar_1_minus">-</string>
    <string name="progressbar_1_default_progress">Default progress:</string>
    <string name="progressbar_1_secondary_progress">Secondary progress:</string>

 

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

ProgressBar Demo3  (0) 2013.08.13
ProgressBar Demo2 -> 원형 프로그레스 바  (0) 2013.08.13
Image Demo  (0) 2013.08.13
AutoText Demo 자동완성 텍스트뷰  (0) 2013.08.13
Spinner Demo  (0) 2013.08.13

+ Recent posts