2012-03-14 3 views
4

android 용 모달 텍스트 입력 대화 상자를 만드는 가장 좋은 방법은 무엇입니까?Android에서 텍스트 입력 대화 상자를 만들려면 어떻게해야합니까?

사용자가 텍스트를 입력하고 확인 버튼을 클릭 한 다음 awt의 모달 대화 상자와 마찬가지로 대화 상자에서 텍스트를 추출 할 때까지 차단하고 싶습니다.

감사합니다.

+0

final Dialog commentDialog = new Dialog(this); commentDialog.setContentView(R.layout.reply); Button okBtn = (Button) commentDialog.findViewById(R.id.ok); okBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //do anything you want here before close the dialog commentDialog.dismiss(); } }); Button cancelBtn = (Button) commentDialog.findViewById(R.id.cancel); cancelBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { commentDialog.dismiss(); } }); 

reply.xml를? – Lucifer

답변

7

이 시도입니다 : 당신이에서 InputBox 유형을 의미

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
     android:layout_width="fill_parent" android:layout_height="fill_parent"  android:background="#ffffff"> 

    <EditText android:layout_width="fill_parent" 
      android:layout_gravity="center" android:layout_height="wrap_content" 
      android:hint="@string/your_comment" android:id="@+id/body" android:textColor="#000000" 
      android:lines="3" /> 
    <LinearLayout android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 
      <Button android:id="@+id/ok" android:layout_height="wrap_content" 
        android:layout_width="wrap_content" android:text="@string/send" android:layout_weight="1" 
        /> 
      <Button android:id="@+id/cancel" android:layout_height="wrap_content" 
        android:layout_width="wrap_content" android:layout_weight="1" 
        android:text="@android:string/cancel" /> 
    </LinearLayout> 
</LinearLayout> 
+4

대화 상자를 표시하려면이 항목을 추가하십시오. commentDialog.show(); – Sahil

+0

왜 나머지 스타일이 같은 스타일을 공유하지 않습니까? – FtheBuilder

2

XML 레이아웃을 사용하여 사용자 지정 대화 상자를 만들 수 있습니다. 그리고 사용자가 텍스트를 입력하고 확인 버튼을 누를 때까지 차단하려는 경우 setCancelable(false)으로 만들 수 있습니다.

확인 Google 검색 링크 : Dialog With EditText

+0

setCancelable (false)는 단지 피상적입니까? 내 말은 정말로 모든 걸 멈출 수 있니? 내 응용 프로그램에서, 데이터가 수집되는 대화 상자 뒤에있는 활동이 일시 중지되기를 바랍니다. –

1

난 당신이 모달 대화 상자를 의미 생각합니다.

제가 말하려합니다. AlertDialog.Builder 시작으로, 더 새로운 방법은 대화 수명주기를보다 잘 제어 할 수있는 DialogFragment을 사용하는 것입니다.

당신이 찾고있는 주요 방법은 dialog.setCancelable(false);

+0

setCancelable (false)는 단지 피상적입니까? 내 말은 정말로 모든 걸 멈출 수 있니? 내 응용 프로그램에서는 데이터가 수집되는 대화 상자의 뒤에있는 활동이 일시 중지되도록하기를 바랍니다. 즉, 사용자가 대화 상자를 닫을 때까지 데이터 수집이 중지됩니다. 그렇게 할 수 있을까요? –

+0

@perfectionming 나는 새로운 질문을해야한다고 생각한다. –

+1

@ perfectionm1ng 자신의 코드로 "모든 것"을 일시 중지해야합니다. 왜냐하면이 모달 대화 상자는 당신을 위해 그것을 할 수 없기 때문입니다. 어쩌면 call show() 대화 상자 바로 전에 데이터 수집을 일시 중지 할 수 있습니다. –

관련 문제