마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

텍스트뷰의 이벤트가 왜 안먹는지 잘 모르겠습니다. [closed]

0 추천

 

안녕하세용.

제가 텍스트뷰에 임시적으로 온클릭 이벤트를 주어서 100개의 텍스트뷰가 잘 동작하는지 테스트를 하고 있습니다.

텍스트를 클릭함에 따라 텍스트뷰의 이미지가 다르게 뜨도록 하고 있습니다.

그런데 A1 A2 A3 ... A10 까지 한 세트로 되어 있고, 그 세트가 10개까지여서 J1 J2... J10 까지 총 10개의

레이아웃이 구성되어 있습니다. 아래의 XML에서 대략적으로 설명을 해 보았습니다.

그런데, 90개의 텍스트뷰의 온클릭 이벤트만 잘 동작하고, 마지막 열 부분인 나머지 J1부터 J10까지 클릭이벤트가

동작하지 않는데.. 이 부분에 대해 궁금한 점이 있어서 올렸습니다. 왜 이부분만 동작을 하지 않는지

알고싶습니다. 제가 어딜 놓친것 같긴한데.. 분명 자세히 보았는데.. 어디가 문제인지 제 눈에 쉽게 짚히질 않네요.. 소스가 8000자가 넘어서 짤리는 부분은 아래의 댓글 부분에 ㄷ

 

아래는 자바부분입니다.

<자바 소스>
 

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

public class Seat extends AppCompatActivity {

    ArrayList<Integer> mSeat = new ArrayList<>();    
    int adult = R.id.Adult_Seat_00;
    int school_people = R.id.School_Seat_00;

    int mSeatID = R.id.Seat_00;     // 첫번째 ID
    int mTotal_Count = 0;       
    int mAdult_Count = 0;       
    int mSchool_Count = 0;      

    int Adult_Bacground;          // 기존에 선택된 어른 필드값 Id
    int School_Bacground;        // 기존에 선택된 학생 필드값 Id
    

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

        init();
        initSeat();

    }


    private void init() {
        for (int i = 0; i < 9; i++) {
            findViewById(R.id.Selection_Success).setOnClickListener(mOnClickListener);
            findViewById(adult + i).setOnClickListener(mOnClickListener);
            findViewById(school_people + i).setOnClickListener(mOnClickListener);
        }
    }




   

 

질문을 종료한 이유: 종료종료종료종료종료종료종료종료종료종료종료종료종료종료
비선아 (920 포인트) 님이 2016년 11월 23일 질문
비선아님이 2016년 11월 26일 closed
void initSeat() {
        for (int i = 0; i < 99; i++) {
            if (mSeat.size() !=100) {
                mSeat.add(mSeatID + i);
                findViewById(mSeatID + i).setOnClickListener(mOnClickListener);
            }
            if (i < 5) {
                findViewById(mSeatID + i).setBackgroundResource(R.drawable.handicapped_checkbox_img);
            } else {
                findViewById(mSeatID + i).setBackgroundResource(R.drawable.box_image);
            }
        }
    }


 View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            System.out.println("@@@");
            if (mSeat.contains(v.getId())) {    
                // 클릭한건지 판단하는 조건문
                initSeat();
          
                for (int i = v.getId(); i < v.getId() + mTotal_Count; i++) {
                    // 총 션택수 만큼 이미지 교체
                    findViewById(i).setBackgroundResource(R.drawable.selected_box_image);
                }

                return;
            }

            
            if (v.getId() == R.id.Selection_Success) {
                mTotal_Count = mAdult_Count + mSenior_Count + mSchool_Count;

                findViewById(R.id.choiii).setVisibility(View.GONE);    
                initSeat();
                return;
            }

            for (int i = 0; i < 9; i++) {
                if (v.getId() == adult + i) {
                    mAdult_Count = Integer.parseInt(((TextView) v).getText().toString());
                    if (Adult_Bacground != 0) {     // 기존에 선택된 값이 있다면 흰색으로 배경변경
                        findViewById(Adult_Bacground).setBackgroundResource(R.drawable.box_image);
                    }
                    v.setBackgroundResource(R.drawable.selected_box_image); // 지금 선택된 필드 녹색으로 배경변경
                    Adult_Bacground = v.getId();
                    TextView Adult_number_txtview = (TextView) findViewById(R.id.Adult_number);
                    Adult_number_txtview.setText(mAdult_Count + "");

                } else  (v.getId() == school_people + i) {
                    mSchool_Count = Integer.parseInt(((TextView) v).getText().toString());
                    if (School_Bacground != 0) {
                        findViewById(School_Bacground).setBackgroundResource(R.drawable.box_image);
                    }
                    School_Bacground = v.getId();
                    v.setBackgroundResource(R.drawable.selected_box_image);

                    TextView School_number_txtview = (TextView) findViewById(R.id.School_number);
                    School_number_txtview.setText(mSchool_Count + "");

                }
            }
        }
    };
}
xml에 대한 코드는 아래와 같습니다.

<LinearLayout
    android:id="@+id/First_Seat_Layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/screen_layout"
    android:orientation="horizontal"
    android:layout_marginTop="10dp"
    android:weightSum="21">

    <TextView
        android:id="@+id/Seat_00"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/handicapped_checkbox_img"
        android:textColor="#000000"
        android:paddingTop="10dp"
        android:layout_weight="2"
        android:text="A1"
        android:textAlignment="center"
        />

    <TextView
        android:id="@+id/Seat_01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:paddingTop="10dp"
        android:text="A2"
        android:textColor="#000000"
        android:textAlignment="center"
        android:background="@drawable/handicapped_checkbox_img"/>


    <TextView
        android:id="@+id/Seat_02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="A3"
        android:textAlignment="center"
        android:paddingTop="10dp"
        android:textColor="#000000"
        android:background="@drawable/handicapped_checkbox_img"/>


    <TextView
        android:id="@+id/Seat_03"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="A4"
        android:paddingTop="10dp"
        android:textColor="#000000"
        android:textAlignment="center"
        android:background="@drawable/handicapped_checkbox_img"/>


    <TextView
        android:id="@+id/Seat_04"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:paddingTop="10dp"
        android:text="A5"
        android:textAlignment="center"
        android:textColor="#000000"
        android:background="@drawable/handicapped_checkbox_img"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"
        />

    <TextView
        android:id="@+id/Seat_05"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="A6"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_06"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="A7"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_07"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="A8"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"/>

    <TextView
        android:id="@+id/Seat_08"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#000000"
        android:text="A9"
        android:background="@drawable/box_image"/>

    <TextView
        android:id="@+id/Seat_09"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#000000"
        android:text="A10"
        android:background="@drawable/box_image"/>

</LinearLayout>

<LinearLayout
    android:id="@+id/Second_Seat_Layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/First_Seat_Layout"
    android:orientation="horizontal"
    android:weightSum="21">

    <TextView
        android:id="@+id/Seat_11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/box_image"
        android:textColor="#000000"
        android:paddingTop="10dp"
        android:layout_weight="2"
        android:text="B1"
        android:textAlignment="center"
        />

    <TextView
        android:id="@+id/Seat_12"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:paddingTop="10dp"
        android:text="B2"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_13"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="B3"
        android:textAlignment="center"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_14"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="B4"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:paddingTop="10dp"
        android:text="B5"
        android:background="@drawable/box_image"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"
        />

    <TextView
        android:id="@+id/Seat_16"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="B6"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="B7"
        android:background="@drawable/box_image"/>


    <TextView
        android:id="@+id/Seat_18"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:text="B8"
        android:paddingTop="10dp"
        android:background="@drawable/box_image"/>

    <TextView
        android:id="@+id/Seat_19"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#000000"
        android:text="B9"
        android:background="@drawable/box_image"/>

    <TextView
        android:id="@+id/Seat_20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:textColor="#000000"
        android:text="B10"
        android:background="@drawable/box_image"/>

</LinearLayout>

1개의 답변

0 추천
해당 프로젝트의 R.java 에

int adult = R.id.Adult_Seat_00;
int school_people = R.id.School_Seat_00;

값과 그 이후의 값들이 어떻게 선언되어 있는지 확인하세요

그리고 아이디를 저렇게 쓰는거 아닙니다.

우선 기본 책이라도 읽으세요. 개발에 모든걸 QnA를 통해서 하면 어떻합니까?
aucd29 (218,390 포인트) 님이 2016년 11월 24일 답변
...