2011-08-03 4 views
1

Android의 토스트에 이미지를 표시하고 싶습니다.토스트에 이미지를 표시 할 수 없습니다.

<?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="#CCCCCC" 
    android:weightSum="1" android:id="@+id/llid"> 
    <EditText 
     android:id="@+id/cpuText" 
     android:hint="Enter cpu" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 
    </EditText> 
    <EditText 
     android:id="@+id/ramText" 
     android:hint="Enter ram" 
     android:layout_height="wrap_content"  
     android:layout_width="fill_parent"> 
    </EditText> 
    <EditText 
     android:id="@+id/bandwidthText" 
     android:hint="Enter bandwidth" 
     android:layout_height="wrap_content"  
     android:layout_width="fill_parent"> 
    </EditText> 
    <Button 
     android:id="@+id/imageRequestButton" 
     android:layout_height="wrap_content" 
     android:text="Download" 
     android:layout_width="fill_parent" android:onClick="sendImageRequest"> 
    </Button>  
    <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="#00FF00" 
     android:weightSum="1" android:id="@+id/svllid"> 
     <TextView android:text="client profile" 
      android:id="@+id/profileName" 
      android:layout_width="fill_parent" 
      android:textStyle="bold" 
      android:layout_height="wrap_content" 
      android:gravity="center_horizontal" 
      android:background="#000000"> 
     </TextView> 
     <TableLayout 
      android:paddingBottom="3pt" 
      android:background="#0000FF" 
      android:layout_width="fill_parent" 
      xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content"> 
      <TableRow> 
       <TextView 
        android:paddingLeft="3pt" 
        android:paddingTop="3pt" 
        android:text="Image Name" 
        android:layout_width="150px" 
        android:layout_height="wrap_content" 
        android:textColor="#FFFFFF"/> 
       <TextView 
        android:paddingLeft="3pt" 
        android:text="blah.png" 
        android:textColor="#FFFFFF" 
        android:layout_width="315px" 
        android:layout_height="wrap_content" android:id="@+id/imageName"/>   
      </TableRow> 
      <TableRow> 
       <TextView 
        android:paddingLeft="3pt" 
        android:text="Size" 
        android:layout_width="150px" 
        android:layout_height="wrap_content" 
        android:textColor="#FFFFFF"/> 
       <TextView 
        android:paddingLeft="3pt" 
        android:text="155kb" 
        android:textColor="#FFFFFF" 
        android:layout_width="300px" 
        android:layout_height="wrap_content" android:id="@+id/imageSize"/>   
      </TableRow> 
      <TableRow> 
       <TextView 
        android:paddingLeft="3pt" 
        android:text="Dimensions" 
        android:layout_width="150px" 
        android:layout_height="wrap_content" 
        android:textColor="#FFFFFF"/> 
       <TextView 
        android:paddingLeft="3pt" 
        android:text="250 X 150px" 
        android:textColor="#FFFFFF" 
        android:layout_width="300px" 
        android:layout_height="wrap_content" android:id="@+id/imageDimension"/>   
      </TableRow>       
     </TableLayout>           
    </LinearLayout> 
</LinearLayout> 

내가 ID 으로있는 LinearLayout을 보여주고 싶은에을 'svllid'내 layout.xml에서, 정말 같은 텍스트 뷰와 TableLayout을가 포함 된있는 LinearLayout 'svllid'를 정의 토스트하고 내 활동 코드에서 축배를 보여라.

이제 실제 로이드 코드, I는 제 I은 SOAP 메시지로부터 화상을 판독해서

setContentView(R.layout.main); 

전화. 그런 다음 ImageView를 만들고이를 LinearLayout 'svllid'에 삽입하고 Android 토스트에 LinearLayout을 표시하려고합니다.

   Toast imageToast = new Toast(this); 
       LinearLayout toastLayout = (LinearLayout) findViewById(R.id.svllid); 
       toastLayout.addView(image,1); 
       imageToast.setView(toastLayout); 
       imageToast.setDuration(Toast.LENGTH_LONG); 
       imageToast.show(); 

그러나 작동하지 않습니다. 내 응용 프로그램이 다음 오류로 인해 충돌합니다.

java.lang.IllegalArgumentException: View not attached to window manager 

이유가 무엇입니까?

+1

이렇게하면 안됩니다. 당신의 svllid가 이미 활동 중입니다. 다시 토스트에 추가 할 수 없습니다. 새로운 뷰를 프로그래밍 방식으로 만들거나 다른 레이아웃을 '부 풀리기', 토스트를 위해'setView()'를 만들어야 할 수도 있습니다. – Varun

+0

그래서 main.xml에서 'svllid'를 꺼내서 프로그래밍 방식으로 생성해야합니까? – Joeblackdev

+1

예. 그것을 별도의 XML에 보관하십시오. 'LayoutInflator'를 사용하여 새 XML을 부 풀린 다음 토스트로 설정하십시오. 또는 프로그래밍 방식으로 만들고 토스트로 설정하십시오. – Varun

답변

1

루트 레이아웃에 특정 ID를 사용해야한다고 생각합니다. "toast_layout"또는 "toast_layout_root"라는 이름을 지정해야합니다. 어느 쪽을 사용해야하는지 확실하지 않습니다. 문서가 약간 모호합니다. 둘 다 시도하십시오.

그리고 Varun은 레이아웃을 자체 레이아웃 파일에 넣어야한다고 말했습니다.

는 이미지를 표시하는 사용자 정의 토스트를 사용할 수 있습니다이 들어 Android Doc's and follow the given example.

+0

완벽한, 고맙습니다. – Joeblackdev

-1

을 읽어보십시오.

This을 참조하십시오.

+0

이미지를 표시 할 수있는 맞춤 토스트 사용. –

관련 문제