package com.example.mycross_ap2;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class DialogActivity extends Dialog implements OnTouchListener {

 static int temp;
 String[] answer1 = { "copy", "cat", "tap" };
 String[] answer2 = { "123", "123", "123" };
 String[] answer3 = { "123", "123", "123" };
 String[] answertemp;
 String msg;

 public DialogActivity(Context context) {
  super(context);
 }

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

  switch (0) {
  case 0:
   answertemp = answer1;
   break;
  case 1:
   answertemp = answer2;
   break;
  case 2:
   answertemp = answer3;
   break;

  default:
   break;
  }

  final EditText text = (EditText) findViewById(R.id.dialog_ET1);
  final Button answer = (Button) findViewById(R.id.dialog_btn1);
  
  TextWatcher watcher =  new TextWatcher() {
   @Override
   public void onTextChanged(CharSequence s, int start, int before, int count) {
    msg = text.getText().toString();
    
   }
   
   @Override
   public void beforeTextChanged(CharSequence s, int start, int count,
     int after) {
    // TODO Auto-generated method stub
    
   }
   
   @Override
   public void afterTextChanged(Editable s) {
    
   }
  };
  
  text.addTextChangedListener(watcher);
  
  answer.setOnTouchListener(new OnTouchListener() {

   
   @Override
   public boolean onTouch(View v, MotionEvent event) {
    
    if(msg=="copy")
     dismiss();

    return false;
   }
  });
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getLayoutInflater().inflate(R.menu.dialog, (ViewGroup) menu);
  return true;
 }

 @Override
 public boolean onTouch(View v, MotionEvent event) {
  // TODO Auto-generated method stub
  return false;
 }

}

 

-------

 

입력값이 일치하면 다이얼로그가 꺼지게 하려는데 되지가 않네요 ㅠㅠ 고수분들 도와주세요 ㅠㅠ