편집 기록

편집 기록
  • 프로필 허대영(소프트웨어융합대학)님의 편집
    날짜2016.09.30

    왜 버튼을 한번 더 눌러야 실행될까요?


    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout
        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:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/name_0"
                android:layout_weight="0.8">
    
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1.5">
    
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1">
    
                <ImageButton
                    android:id="@+id/button042"
                    android:onClick="onButton042Clicked"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/n_arrow" />
    
            </LinearLayout>
    
    
        </LinearLayout>
    
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="10dp"
            android:layout_weight="1">
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:id="@+id/mini003"
                android:src="@drawable/dt_3"
                android:visibility="invisible"
                />
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:id="@+id/mini002"
                android:src="@drawable/dt_2"
                android:visibility="invisible"
                />
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:id="@+id/mini001"
                android:src="@drawable/dt_1"
                android:visibility="visible"
                />
    
        </FrameLayout>
    
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="65dp"
            android:layout_marginBottom="5dp"
            android:orientation="horizontal">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5">
    
                <ImageButton
                    android:id="@+id/button043"
                    android:onClick="onButton043Clicked"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/tube_1" />
    
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1.2">
    
            </LinearLayout>
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.8">
    
                <ImageButton
                    android:id="@+id/button040"
                    android:onClick="onButton040Clicked"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/back_1" />
    
            </LinearLayout>
    
    
        </LinearLayout>
    
    
    </LinearLayout>
    

    제 layout코드 입니다... 딴건 별로 중요한거 없고...

    상단에 다음으로 넘어가는 이미지 버튼을 넣구요...

    넘길 이미지 3개를 넣어놨습니다...

    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.ImageView;
    import android.widget.ViewFlipper;
    import android.widget.Button;
    import android.widget.Toast;
    
    public class DetailActivity extends AppCompatActivity {
    
        ImageView mini001;
        ImageView mini002;
        ImageView mini003;
    
        int imageIndex = 0;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.minirobo_detail);
    
            mini001 = (ImageView) findViewById(R.id.mini001);
            mini002 = (ImageView) findViewById(R.id.mini002);
            mini003 = (ImageView) findViewById(R.id.mini003);
    
        }
    
    
        public void onButton042Clicked(View v) {
            changeImage1();
        }
    
        private void changeImage1() {
            if (imageIndex == 0) {
                mini001.setVisibility(View.VISIBLE);
                mini002.setVisibility(View.INVISIBLE);
                mini003.setVisibility(View.INVISIBLE);
    
                imageIndex = 1;
            } else if (imageIndex == 1)
    
            {
                mini001.setVisibility(View.INVISIBLE);
                mini002.setVisibility(View.VISIBLE);
                mini003.setVisibility(View.INVISIBLE);
    
                imageIndex = 2;
    
            } else if (imageIndex == 2)
    
            {
                mini001.setVisibility(View.INVISIBLE);
                mini002.setVisibility(View.INVISIBLE);
                mini003.setVisibility(View.VISIBLE);
    
                imageIndex = 0;
            }
        }
    
        public void onButton043Clicked(View v) {
            Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=7DzwSecg2zA"));
            startActivity(myIntent);
        }
    
    
        public void onButton040Clicked(View v) {
            finish();
        }
    
        }
    

    이게 제 자바 파일입니다...

    다음버튼을 누를때마다 하나씩 visible로 바꿔 뜨게 하고 있습니다...

    뭐 기능은 잘 작동하는데...

    이상하게 최초 다음사진으로 넘기는 버튼만 스킵이 되네요...

    말이 좀 애매한데...

    처음 다음사진 누르면 아무일 없고... 두번째부터 누를때마다 다음사진으로 넘어갑니다...

    큰 문제는 안되지만 이게 왜 2번째 눌렀을때부터 동작하는지 알수 있을까요??

  • 프로필 알 수 없는 사용자님의 편집
    날짜2016.09.30

    왜 버튼을 한번 더 눌러야 실행될까요?


    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_marginTop="5dp"
        android:orientation="horizontal">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/name_0"
            android:layout_weight="0.8">
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.5">
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1">
    
            <ImageButton
                android:id="@+id/button042"
                android:onClick="onButton042Clicked"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/n_arrow" />
    
        </LinearLayout>
    
    
    </LinearLayout>
    
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dp"
        android:layout_weight="1">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:id="@+id/mini003"
            android:src="@drawable/dt_3"
            android:visibility="invisible"
            />
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:id="@+id/mini002"
            android:src="@drawable/dt_2"
            android:visibility="invisible"
            />
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:id="@+id/mini001"
            android:src="@drawable/dt_1"
            android:visibility="visible"
            />
    
    </FrameLayout>
    
    
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_marginBottom="5dp"
        android:orientation="horizontal">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.5">
    
            <ImageButton
                android:id="@+id/button043"
                android:onClick="onButton043Clicked"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/tube_1" />
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.2">
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="0.8">
    
            <ImageButton
                android:id="@+id/button040"
                android:onClick="onButton040Clicked"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/back_1" />
    
        </LinearLayout>
    
    
    </LinearLayout>
    

    ================================================

    제 layout코드 입니다... 딴건 별로 중요한거 없고...

    상단에 다음으로 넘어가는 이미지 버튼을 넣구요...

    넘길 이미지 3개를 넣어놨습니다...

    ===============================================

    import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.ImageView; import android.widget.ViewFlipper; import android.widget.Button; import android.widget.Toast;

    public class DetailActivity extends AppCompatActivity {

    ImageView mini001;
    ImageView mini002;
    ImageView mini003;
    
    int imageIndex = 0;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.minirobo_detail);
    
        mini001 = (ImageView) findViewById(R.id.mini001);
        mini002 = (ImageView) findViewById(R.id.mini002);
        mini003 = (ImageView) findViewById(R.id.mini003);
    
    }
    
    
    public void onButton042Clicked(View v) {
        changeImage1();
    }
    
    private void changeImage1() {
        if (imageIndex == 0) {
            mini001.setVisibility(View.VISIBLE);
            mini002.setVisibility(View.INVISIBLE);
            mini003.setVisibility(View.INVISIBLE);
    
            imageIndex = 1;
        } else if (imageIndex == 1)
    
        {
            mini001.setVisibility(View.INVISIBLE);
            mini002.setVisibility(View.VISIBLE);
            mini003.setVisibility(View.INVISIBLE);
    
            imageIndex = 2;
    
        } else if (imageIndex == 2)
    
        {
            mini001.setVisibility(View.INVISIBLE);
            mini002.setVisibility(View.INVISIBLE);
            mini003.setVisibility(View.VISIBLE);
    
            imageIndex = 0;
        }
    }
    
    public void onButton043Clicked(View v) {
        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/watch?v=7DzwSecg2zA"));
        startActivity(myIntent);
    }
    
    
    public void onButton040Clicked(View v) {
        finish();
    }
    
    }
    

    ===============================================

    이게 제 자바 파일입니다...

    다음버튼을 누를때마다 하나씩 visible로 바꿔 뜨게 하고 있습니다...

    뭐 기능은 잘 작동하는데...

    이상하게 최초 다음사진으로 넘기는 버튼만 스킵이 되네요...

    말이 좀 애매한데...

    처음 다음사진 누르면 아무일 없고... 두번째부터 누를때마다 다음사진으로 넘어갑니다...

    큰 문제는 안되지만 이게 왜 2번째 눌렀을때부터 동작하는지 알수 있을까요??