안드로이드

 

 

 

 

 

 

 

 

 

 

 

           

 

     

 

.

 

class MainActivity

 

package org.androidtown.myprogress;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    ProgressBar progressBar;
    SeekBar seekBar;
    TextView textView;
    Toast toast;


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

        progressBar =(ProgressBar)findViewById(R.id.progressBar);
        seekBar=(SeekBar)findViewById(R.id.seekBar);
        textView =(TextView)findViewById(R.id.textView);

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

           //시크바 가 변경되었을때 자동적으로 호출
            // 쓰레드 설정 없이 동작이 가능하다.
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                textView.setText("설정된 값 :" + progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

    }


    public void onButton1Clicked(View v){
        progressBar.setProgress(50);
    }


    public void onButton2Clicked(View v){
        ProgressDialog dialog =new ProgressDialog(this);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setTitle("진행상태");
        dialog.setMessage("데이터를 확인하는 중입니다.");

        dialog.show();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

        getMenuInflater().inflate(R.menu.menu, menu);

        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id =item.getItemId();

        if(id==R.id.action0){
            tostShow("나다 메뉴가 선택되었습니다.");
            return true;
        }else if(id==R.id.action1){
            tostShow( "검색 메뉴가 선택되었습니다.");
            return true;
        }else if(id==R.id.action2){
            tostShow("이미지뷰 메뉴가 선택되었습니다.");
            return true;
        }

        return super.onOptionsItemSelected(item);
    }



    public void tostShow(String text){

        if(toast==null){
            toast=Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT);
        }else{
            toast.setText(text);
        }
        toast.show();
    }


}

 

R.layout.activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    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="org.androidtown.myprogress.MainActivity">

    <ProgressBar
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:max="100" />

    <Button
        android:text="진행상태값 설정하기"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="65dp"
        android:id="@+id/button"
        android:onClick="onButton1Clicked"
        android:layout_below="@+id/progressBar"
        android:layout_centerHorizontal="true" />

    <Button
        android:text="진행상태 대화상자 띄우기"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:id="@+id/button2"
        android:onClick="onButton2Clicked"
        android:layout_below="@+id/button"
        android:layout_centerHorizontal="true" />

    <SeekBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="74dp"
        android:id="@+id/seekBar"
        android:layout_below="@+id/button2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:max="100"
        />


    <TextView
        android:text="설정한 값 :0"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/seekBar"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="52dp"
        android:id="@+id/textView" />


</RelativeLayout>

 

R.menu.menu

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <item android:id="@+id/action0"
        android:title="nada"
        android:orderInCategory="100"
        app:showAsAction="never"
        />

    <item android:id="@+id/action1"
        android:title="검색"
        android:icon="@drawable/a1"
        android:orderInCategory="101"
        app:showAsAction="always"
        />

    <item android:id="@+id/action2"
        android:title="이미지뷰"
        android:icon="@drawable/a2"
        android:orderInCategory="101"
        app:showAsAction="always"
        />
   <!-- always 를-->


</menu>

 

 

시크바 

      seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

           //시크바 가 변경되었을때 자동적으로 호출
            // 쓰레드 설정 없이 동작이 가능하다.
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                textView.setText("설정된 값 :" + progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

 

 

 

 

프로그레스바

    public void onButton2Clicked(View v){
        ProgressDialog dialog =new ProgressDialog(this);
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        dialog.setTitle("진행상태");
        dialog.setMessage("데이터를 확인하는 중입니다.");

        dialog.show();
    }

 

 

 

옵션메뉴

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        int id =item.getItemId();

        if(id==R.id.action0){
            tostShow("나다 메뉴가 선택되었습니다.");
            return true;
        }else if(id==R.id.action1){
            tostShow( "검색 메뉴가 선택되었습니다.");
            return true;
        }else if(id==R.id.action2){
            tostShow("이미지뷰 메뉴가 선택되었습니다.");
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

 

 

51강

 

 

 

 

 

52강

 

 

 

about author

PHRASE

Level 60  머나먼나라

육체적인 요구를 만족시켜 주는 것은 만족스런 생활에 불가결한 선행 조건이지만, 그것만으로는 충분하지 않다. 만족스런 생활을 영위하기 위해서 사람은 자기의 독자적 특징이나 능력에 맞는 정도로 자기의 지능 및 예술적 능력을 개발할 수 있는 가능성을 또한 가져야만 한다. -아인슈타인

댓글 ( 4)

댓글 남기기

작성