2014-10-24 11 views
0

오류가 발생하면 'AlertDialog'가 표시되며 '오류, 추가 할 수 없음/무엇이든지', 결과도 표시됩니다. 내가 구문 분석을 좋아하지만 모든 사용자 만 예외 '세부 정보'를 클릭하고 읽고 싶은 것들에 표시되지하려는 예외.'자세한 내용을 보려면'확장 가능 필드를 Android의 AlertDialog에 추가하는 방법

  AlertDialog.Builder dialogo1 = new AlertDialog.Builder(activity); 
      dialogo1.setTitle("Error"); 
      dialogo1.setMessage("Could not update movie: " + result); 
      dialogo1.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialogo1, int id) { 
        activity.finish(); 
       } 
      }); 
      dialogo1.show(); 

내 코드는 바로, 아주 간단합니다,있다? 어쨌든이 대답을 찾을 수 없었습니다. 그냥 가능하지 않다고 생각하기 시작했습니다.

+1

여기서 사용자 지정보기가있는 DialogFragment를 사용하는 것이 더 깔끔합니다. 시스템 버튼을 사용하는 대신 숨겨진 필드의 가시성을 변경하기 위해 고유 버튼을 추가 할 수 있습니다. – reactivemobile

+0

google.com + 대화 + 사용자 정의보기 – Selvin

+0

그리고 대화 상자를 닫기 전에 activity.finish()가 있습니다. 창 누설 오류가 발생하지 않았습니까? – Droidekas

답변

0

원하는 경고 대화 상자가 있습니다. 우리에게 레이아웃을 가지고 당신이 정의하는 일반보기처럼 당신의 dialog.Then이 청취자 등을 초기화 정의

dialog_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<ImageView 
    android:src="@drawable/header_logo" 
    android:layout_width="match_parent" 
    android:layout_height="64dp" 
    android:scaleType="center" 
    android:background="#FFFFBB33" 
    android:contentDescription="@string/app_name" /> 
<TextView 
    android:id="@+id/error" 
    andorid:text="Error Message" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
<Button 
    android:id="@+id/moreDetailsButton" 
    android:text="Click for more details" 
    android:inputType="textPassword" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 
<TextView 
    android:id="@+id/moreDetailsView" 
    android:text="Click for more details" 
    android:inputType="textPassword" 
    android:layout_width="match_parent" 
    android:visibility="gone"; 
    android:layout_height="wrap_content"/> 
    <Button 
    android:id="@+id/dialogButtonOK" 
    android:layout_width="100px" 
    android:layout_height="wrap_content" 
    android:text=" Ok " 
    android:layout_marginTop="5dp" 
    android:layout_marginRight="5dp" 
    android:layout_below="@+id/moreDetailsButton" 
    /> 
</RelativeLayout> 

및 클래스의

final Dialog dialog = new Dialog(context); 
dialog.setContentView(R.layout.dialog_layout); 
TextView error=(TextView)dialog.findViewById(R.id.error); 
Button errorButton=(Button)dialog.findViewById(R.id.moreDetailsButton); 
Button okButton=(Button)dialog.findViewById(R.id.ok); 


//Do whatever you want with the rest of the dialog 
// initialize all the onclick listeners a usual 


errorButton.setOnClickListener(new View.onClickListener(){ 

    @Override 
    public void onClick(View v){ 
     TextView errorDetails=(TextView)dialog.findViewById(R.id.moreDetailsView); 
     errorDetails.setText(detailedErrorMessage) //add the details to this text view; 
     errorDetails.setVisibility(View.VISIBLE); 
     }  
}); 

dialog.show(); 

ctrl + c, ctrl + v이 작동하지 않는 경우 구문 적으로 오류가 있으면 미안합니다. 내 IDE는 오늘 오작동하기로 결정했습니다.

사용자 지정 경고 대화 상자에 대한 자세한 내용은 this을 따르십시오.

+0

레이아웃이 다소 엉뚱한, 나는 대답에 내 자신의 버전을 쓸 것입니다. 저를 올바른 방향으로 가리켜 주셔서 감사합니다! – user2013543

0
<?xml version="1.0" encoding="utf-8"?> 

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

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView 
      android:id="@+id/error" 
      android:text="Error Message" 
      android:layout_width="match_parent" 
      android:layout_height="37dp" 
      android:layout_toEndOf="@+id/moreDetailsView" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:id="@+id/moreDetailsView" 
      android:text="No existen detalles para este tipo de error." 
      android:layout_width="match_parent" 
      android:visibility="gone" 
      android:layout_height="wrap_content" /> 

     <Button 
      android:id="@+id/moreDetailsButton" 
      android:text="Click for more details" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toEndOf="@+id/moreDetailsView" 
      android:layout_below="@+id/error" 
      android:layout_alignParentStart="true" /> 

     <Button 
      android:id="@+id/dialogButtonOK" 
      android:layout_width="139dp" 
      android:layout_height="wrap_content" 
      android:text="OK" 
      android:layout_centerVertical="true" 
      android:layout_toEndOf="@+id/moreDetailsView" 
      android:layout_gravity="center_horizontal" /> 
    </LinearLayout> 

</RelativeLayout>