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

버튼을 눌러도 숫자의 변화가 없는데 어떻게 해야되나요?

0 추천

다음과 같이 작성을 하였는데요 

버튼을 눌러도 text뷰에 변화가 없는데 어디서 잘못 된건지 모르겠습니다.

메인 액티비티.

public class Content_Main extends Fragment implements View.OnClickListener, SeekBar.OnSeekBarChangeListener {
    
    private  int brightness = 0;
    private  int count;

    ProgressBar mtimerbar = null;

    Button mhz_left;
    Button mhz_right;

    String message;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View RootView = inflater.inflate(R.layout.content_main, container, false);
        // onCreateView = Layout을 inflater하여 View작업을 하는 곳
        final ArcSeekBar arcSeekBar = (ArcSeekBar)RootView.findViewById(R.id.seekArc);
        mhztext = (TextView)RootView.findViewById(R.id.hztext);
        mtimebar = (TextView)RootView.findViewById(R.id.timebar);

        mhz_left=(Button)RootView.findViewById(R.id.hz_left);
        mhz_right=(Button)RootView.findViewById(R.id.hz_right);
     
        mhz_left.setOnClickListener(this);
        mhz_right.setOnClickListener(this);

        arcSeekBar.setProgress(0);
        mhztext.setText("");


        return RootView;
    }

    protected void initView(View root) {

        //tick_drawable
        IndicatorSeekBar tick_drawable = root.findViewById(R.id.seekBar);
        tick_drawable.setTickMarksDrawable(getResources().getDrawable(R.mipmap.ic_launcher));

    }

    @Override
    public void onClick(View v) {switch(v.getId()) {// Hz -1
        case R.id.hz_left:
            count--;
            mhztext.setText(""+count);
            message = "down";
            if(message != null && message.length() > 0)
                sendMessage(message);
            break;

        // Hz +1
        case R.id.hz_right:
            count++;
            mhztext.setText(""+count);
            message = "up";
            if(message != null && message.length() > 0)
                sendMessage(message);
            break;
        default:
            break;
        }

    }

xml

<!-- Hz -->
    <TextView
        android:id="@+id/hztext"
        android:layout_width="40dp"
        android:layout_height="44dp"
        android:layout_marginLeft="70dp"
        android:layout_marginStart="70dp"
        android:gravity="center"
        android:text="0"
        android:textColor="#ffffff"
        android:textSize="35sp"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <!-- Hz down 버튼 -->
    <Button
        android:id="@+id/hz_left"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_marginLeft="50dp"
        android:layout_marginStart="50dp"
        android:background="@drawable/arrow_left_black"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <!-- Hz up 버튼 -->
    <Button
        android:id="@+id/hz_right"
        android:layout_width="20dp"
        android:layout_height="30dp"
        android:layout_marginLeft="110dp"
        android:layout_marginStart="110dp"
        android:background="@drawable/arrow_right_black"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintStart_toStartOf="@+id/imageView"
        app:layout_constraintTop_toTopOf="@+id/imageView" />
익명사용자 님이 2018년 9월 27일 질문

1개의 답변

0 추천
정상적으로 onClick이 호출되는지  switch 문 앞에 로그를 출력해 보세요

 public void onClick(View v) {

Log.d("Content_Main","onClick:"+v.getId());

switch(v.getId())

....

}
luxsoft (1,780 포인트) 님이 2018년 9월 27일 답변
...