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

안드로이드 dialog edittext

0 추천
input_text.setOnClickListener(new View.OnClickListener() {
   public void onClick(View v) {
       Context ctx = getApplicationContext();
    LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(LAYOUT_INFLATER_SERVICE);
    final View layout = inflater.inflate(R.layout.text,null);
    AlertDialog.Builder aDialog = new AlertDialog.Builder(MainActivity.this);
    aDialog.setTitle("텍스트를 입력해주세요?");
    aDialog.setView(layout);
    
    aDialog.setPositiveButton("확인",
      new DialogInterface.OnClickListener() {

       public void onClick(DialogInterface dialog,
         int which) {

        EditText t = (EditText)layout.findViewById(R.id.image);
        String str = t.getText().toString();
        
        Paper.str = str;
        Paper.draw_text = true;
        Paper.check_text = true;
        Paper.clear_check = false;
        Paper.make_point = false;
        Paper.erase = false;
       }

      });

    aDialog.setNegativeButton("취소",
      new DialogInterface.OnClickListener() {

       public void onClick(DialogInterface dialog,
         int which) {
       }

      });

    AlertDialog ad = aDialog.create();
    ad.show();

   }
  });

버튼 클릭 시 dialog 를 생성해서 확인버튼을 누르면 Paper 클래스 변수에 문자열을 저장하려고하는데요,

Paper.str = "텍스트입니다"; 이렇게 문자열을 지정해서 하면 제대로 결과가 나오는데

Paper.str = edittext.gettext().toString(); 을 하면 null 이 저장되는 것 같습니다.

프로그래밍고수가될거야 (140 포인트) 님이 2014년 2월 22일 질문

1개의 답변

0 추천
글쎄요. 코드 상은 맞는 듯 한데. 안 올려주신 레이아웃 쪽 코드가 다른듯 한데..

R.id.image 가 EditText 맞나요?  맞다면  R.layout.text(text.xml) 파일을 올려 주셔야 확인이 가능할 듯 합니다.
사악미소 (65,330 포인트) 님이 2014년 2월 22일 답변
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:padding="10dp" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="텍스트" >
    </TextView>

    <EditText
        android:id="@+id/image"
        android:layout_width="200dip"
        android:layout_height="35dip"
        android:layout_marginRight="10dp" />
</LinearLayout>

이게 레이아웃코드인데 문제가 없어보입니다.
...