2014-04-24 1 views
-1

EditText가있는 축배를 표시해야하는 응용 프로그램을 만들고 있습니다. 건배 안에 EditText를 만들 수 있습니까?안드로이드에있는 토스트 안의 EditText?

+1

이 대화 상자를 사용하십시오 –

+0

EditText ... hmmm이있는 건배를 표시하십시오. 귀하의 질문에 대한 답을 찾으십시오. EditText에서 "토스트 (toast)"의 기능을 원하십니까? – tambykojak

답변

3

사용자 입력 대화 상자를 사용해야합니다.

단계 :

프롬프트 대화 상자 레이아웃 XML 파일을 만듭니다. AlertDialog.Builder에 프롬프트 대화 상자 레이아웃을 첨부하십시오. AlertDialog.Builder를 AlertDialog에 연결하십시오.

이 행해져 Yout 레이아웃/main_activity.xml

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

     <Button 
      android:id="@+id/buttonPrompt" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Show Prompt Dialog" /> 

     <EditText 
      android:id="@+id/editTextResult" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

     </EditText> 

    </LinearLayout> 

만들기 레이아웃/promtps.xml

<?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/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Type Your Message : " 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <EditText 
     android:id="@+id/editTextDialogUserInput" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <requestFocus /> 

    </EditText> 

</LinearLayout> 

귀하의 MainActivity :

public class MainActivity extends Activity { 

    final Context context = this; 
    private Button button; 
    private EditText result; 

    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // components from main.xml 
     button = (Button) findViewById(R.id.buttonPrompt); 
     result = (EditText) findViewById(R.id.editTextResult); 

     // add button listener 
     button.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 

       // get prompts.xml view 
       LayoutInflater li = LayoutInflater.from(context); 
       View promptsView = li.inflate(R.layout.prompts, null); 

       AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
         context); 

       // set prompts.xml to alertdialog builder 
       alertDialogBuilder.setView(promptsView); 

       final EditText userInput = (EditText) promptsView 
         .findViewById(R.id.editTextDialogUserInput); 

       // set dialog message 
       alertDialogBuilder 
        .setCancelable(false) 
        .setPositiveButton("OK", 
         new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 
         // get user input and set it to result 
         // edit text 
         result.setText(userInput.getText()); 
         } 
         }) 
        .setNegativeButton("Cancel", 
         new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog,int id) { 
         dialog.cancel(); 
         } 
         }); 

       // create alert dialog 
       AlertDialog alertDialog = alertDialogBuilder.create(); 

       // show it 
       alertDialog.show(); 

      } 
     }); 
    } 
} 
+0

thannxx ... 잘 작동합니다. :) – Ruchir

+0

답변을 평가 해주세요.이 스레드를 닫으십시오. – josedlujan

+0

rate my que too plz .. :) – Ruchir

2

축배를 얻을 수있는 뷰가 아니다 내가 올바르게 기억한다면 집중하라. 당신이 말하는 것은 대화입니다.