안드로이드 토스트 메시지 안띄워짐

조회수 1834회

안드로이드 토스트 오류

토스트 코드를 정확히 작성했는데 안됩니다. 로그디버그 찍은것도 공유드립니다. 설정 문제인지, Show() 파일을 건드려서 그런건지 잘 모르겠습니다.

자바 코드

package com.example.textmessagetoastmission04;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    EditText inputMessage;
    TextView inputCount;

    private static final String TAG = "MainActivity";

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

        inputCount = findViewById(R.id.inputCount);
        inputMessage = findViewById(R.id.inputMessage);

        Button sendButton = findViewById(R.id.sendButton);
        sendButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View c) {
                String message = inputMessage.getText().toString();
                Toast.makeText(getApplicationContext(), "전송 메시지 ...\n\n" + message, Toast.LENGTH_LONG).show();
            }
        });
        Log.d(TAG, "onCreate() : ");

        Button closeButton = findViewById(R.id.closeButton);
        closeButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
        Log.d(TAG, "setOnClickListener() : ");

        TextWatcher watcher = new TextWatcher() {
            public void onTextChanged(CharSequence str, int start, int before, int count) {
                try {
                    byte[] bytes = str.toString().getBytes("KSC5601");
                    int strCount = bytes.length;
                    inputCount.setText(strCount + "/ 80바이트");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                Log.d(TAG, "onTextChanged() : ");
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//                String a = s.toString();
//                int b = start
//            }

            public void afterTextChanged(Editable strEditable) {
                String str = strEditable.toString();
                try {
                    byte[] strBytes = str.getBytes();
                    if(strBytes.length > 80) {
                        strEditable.delete(strEditable.length()-2, strEditable.length()-1);
                    }
                } catch(Exception ex) {
                    ex.printStackTrace();
                }
                Log.d(TAG, "afterTextChanged()");
            }

        };
        inputMessage.addTextChangedListener(watcher);
    }
}

레이아웃 코드

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/inputlayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/buttonLayout"
        >

        <EditText
            android:id="@+id/inputMessage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_above="@+id/inputCount"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:cacheColorHint="#00000000"
            android:gravity="top"
            android:listSelector="#00000000"
            android:maxLength="80"
            android:textSize="48sp" />

        <TextView
            android:id="@+id/inputCount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="0 / 80 바이트"
            android:textColor="#ffff00ff"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:textSize="18sp"
            />

    </RelativeLayout>
    <LinearLayout
        android:id="@+id/buttonLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        >
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            >
            <Button
                android:id="@+id/sendButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="전송"
                android:textSize="18sp"
                />
            <Button
                android:id="@+id/closeButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="20dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="닫기"
                android:textSize="18sp"
                />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

매니페스트 코드

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.textmessagetoastmission04">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.TextMessageToastMission04">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

로그캣 코드

2021-07-01 11:03:31.899 17558-17558/com.example.textmessagetoastmission04 D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10158; state: ENABLED
2021-07-01 11:03:31.899 17558-17558/com.example.textmessagetoastmission04 D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10158; state: ENABLED

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)