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

버튼 클릭시에 텍스트뷰가 사라져요... [closed]

0 추천

버튼 클릭 시 택스트뷰에 값을 변경하게끔 구현을 해놓았는데 그게 문제인건지 모르겠습니다.

처음 앱을 시작하면은 텍스트뷰는 출력이 되었있는데 버튼만 누르면 사라집니다.

로그켓에는 문제 없다고 뜨는데요 어떻게 해야될지 모르겠습니다.

public class Content_Main extends Fragment implements View.OnClickListener,SeekBar.OnSeekBarChangeListener {

    private  int count;
    private  int count1;
    private  int progress;
    ProgressBar mtimerbar = null;

    Button hz_left;
    Button hz_right;

    TextView mtimebar;
    TextView mhztext;

    TextView mtextview;

    ArcSeekBar arcSeekBar;
    //int

    String readMessage = null;  
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View RootView = inflater.inflate(R.layout.content_main, container, false);
       
        return RootView;
    }

    protected void initView(View root) {

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

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {  
        super.onActivityCreated(savedInstanceState);

        setUIControl();

        if(ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
            ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);

    }

    private void doDiscovery() {
    }

    @Override
    public void onAttach(Context context) {   
        super.onAttach(context);               
    }

    @Override
    public void onDetach() {                  
        super.onDetach();

        Log.d("Content_Main","Content_Main onDetach");
    }

    @Override
    public void onResume() {                  
        super.onResume();  
        if(flagBindService == false) {
            getActivity().bindService(new Intent(getActivity(), ServiceBluetooth.class), connection, Service.BIND_AUTO_CREATE);
        }
    }

    @Override
    public void onStop() {                      
        super.onStop();

        if(flagBindService){
            flagBindService = false;
            try{
                getActivity().unbindService(connection);
            }catch (Exception e){
                e.printStackTrace();
            }
        }

    }

    /**
     * UI 생성 및 세팅
     */

    private void setUIControl(){

        mBluetoothStatus = (TextView)getView().findViewById(R.id.bluetoothStatus);

        mhztext = (TextView)getView().findViewById(R.id.hztext);
        mtimebar = (TextView)getView().findViewById(R.id.timebar);

        
        hz_left=(Button)getView().findViewById(R.id.hz_left);
        hz_left.setOnClickListener(this);
        hz_right=(Button)getView().findViewById(R.id.hz_right);
        hz_right.setOnClickListener(this);

        arcSeekBar = (ArcSeekBar)getView().findViewById(R.id.seekArc);
        int[] colorArrays = getResources().getIntArray(R.array.gradinet);
        arcSeekBar.setProgressGradient(colorArrays);
        arcSeekBar.setOnProgressChangedListener(new ProgressListener() {
            @Override
            public void invoke(int i) {
                if(progress >0)  {
                    progress--;
                }
                Log.d("Content_Main","sendMessage : "+message);
                mhztext.setText(String.valueOf(progress));
                message = "m";
                if(message != null && message.length() > 0)
                    sendMessage(message);
            }
        });
    }

    private void bluetoothOn(View view){
    }

    private void bluetoothOff(View view){
    }

    // Enter here after user selects "yes" or "no" to enabling radio
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent Data){
        // 응답 요청 확인
        if (requestCode == REQUEST_ENABLE_BT) {
            // 요청 성공 확인
            if (resultCode == RESULT_OK) {
                // The user picked a contact.
                // The Intent's data Uri identifies which contact was selected.
                mBluetoothStatus.setText("Enabled");
            }
            else
                mBluetoothStatus.setText("Disabled");
        }
    }
    @Override
    public void onClick(View v) {
        Log.d("Content_Main","onClick:"+v.getId());
        switch(v.getId()) {
        //  -1
        case R.id.hz_left:
          if(count>0){
             count--;
          }
          mhztext.setText(""+count);
            message = "k";
            if(message != null && message.length() > 0)
                sendMessage(message);
            Log.d("Content_Main","sendMessage : "+message);

          break;

        // +1
        case R.id.hz_right:
           if(count<99){
               count++;
           }
           Log.d("Content_Main","sendMessage : "+message);
           mhztext.setText(""+count);
           message = "j";
            if(message != null && message.length() > 0)
                sendMessage(message);

           break;
        default:
           break;
        }

    }

    private void sendMessage(String message) {

        Log.d("Content_Main","sendMessage : "+message);
        Log.d("Content_Main","sendMessage : "+message);

        if(TextUtils.isEmpty(message)){
            return;
        }

        if(flagBindService && service != null){
            Log.d("Content_Main", "sendMessage to service");
            service.CF_sendMessage(message.getBytes());

            mtimebar.setText("");;
            mhztext.setText("");;
        }
    }

    void OnServiceConnected() {

    }

    void OnBluetoothConnected() {
        ConnectionInfo tmp_info = ConnectionInfo.getInstance(getActivity());
        mBluetoothStatus.setText("Connected "+tmp_info.getDeviceName());
    }

    void OnBluetoothDisconnected() {
        mBluetoothStatus.setText("Connection failed");
    }

    void OnBluetoothMessage(String p_received) {/*

        Log.d("Content_Main","Content_Main received : "+p_received );

        readMessage = p_received;

        if((readMessage.indexOf("s") == 0) && (readMessage.indexOf("j") == 1)&& (readMessage.indexOf("e") == 2)){
            boolean flag = false;
            if(readMessage != null);{
                if(count<99){
                    count++;
            }
                else if(readMessage == null);

            }
        }
        if((readMessage.indexOf("s") == 0) && (readMessage.indexOf("k") == 1)&& (readMessage.indexOf("e") == 2)){
            if(readMessage != null);{
                if(count>0){
                    count--;

                }
                else if(readMessage == null);
            }
        }*/

    }

    void OnBluetoothOn() {

    }

    void OnBluetoothOff() {

    }
}

 

 

질문을 종료한 이유: 해결 하였습니다 프래그먼트에서 설정이 다르게 되어잇어서 발생한 문제 였습니다
익명사용자 님이 2018년 10월 26일 질문
2018년 11월 14일 closed

1개의 답변

0 추천
textView.setText("");

이런 코드 때문에 사실은 있지만, 텍스트뷰에 글자가 없어서 안 보여서 없다고 생각할 수 있습니다. 

너비를 고정값으로 주고 배경색을 표시해서 실제로 없어지는지 확인해보세요.

쎄미 (162,410 포인트) 님이 2018년 10월 26일 답변
백그라운드로 흰색을 주고 글자색을 검은색을 주었을때에 글자만 사라집니다.
버튼클릭시 텍스트에 숫자가 증가하도록 했는데 어디서 수정을 해야될까요?
레이아웃은 다음과 같습니다.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Activity_Main">

    <!-- Hz -->
    <TextView
        android:id="@+id/hztext"
        android:layout_width="40dp"
        android:layout_height="44dp"
        android:layout_marginBottom="1dp"
        android:gravity="center"
        android:text="@string/testtext"
        android:textColor="#000000"
        android:background="#ffffff"
        android:textSize="35sp"
        app:layout_constraintBottom_toBottomOf="@+id/imageView"
        app:layout_constraintEnd_toStartOf="@+id/hz_right"
        app:layout_constraintStart_toEndOf="@+id/hz_left"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- Hz down 버튼 -->
    <Button
        android:id="@+id/hz_left"
        android:layout_width="25dp"
        android:layout_height="40dp"
        android:layout_marginLeft="52dp"
        android:layout_marginStart="52dp"
        android:background="@drawable/arrow_left_black"
        android:contentDescription="@string/todo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <!-- Hz up 버튼 -->
    <Button
        android:id="@+id/hz_right"
        android:layout_width="25dp"
        android:layout_height="40dp"
        android:background="@drawable/arrow_right_black"
        android:contentDescription="@string/todo"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@+id/hztext"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>
@drawable/background 는 무슨 색인가요?
@drawable/background 검은색 계열의 색입니다.
mtimebar, mhztext 둘 다 사라지나요?
ConstraintLayout를 LinearLayout으로 바꿔서 하면 어떤가요?
...