2012-02-23 34 views
0

我有我的顯示對話框顯示我的「自定義位圖圖像」的問題。圖像不是空的。我通過調試模式進行了檢查,並且我的listview已經顯示了它的圖像。對話框上的列表視圖點擊Android 2.3的

我的主要問題是「我是否錯過了一項要求或做了什麼 錯?」。請原諒我這個。我第一次使用對話框。

我還想補充一點,對話框會在點擊時顯示。

我在對話生成的點擊

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    // TODO Auto-generated method stub 
    super.onListItemClick(l, v, position, id); 
    Dialog dialog = new Dialog(A_Test4Activity.this); 
    dialog.setContentView(R.layout.custom_dialog); 
    dialog.setTitle("Title"); 
    TextView tv = (TextView)findViewById(R.id.data1); 
    ImageView iv = (ImageView)findViewById(R.id.dialog_image);   
    try{ 
     Bitmap bm = bm_List.get(position); 
     iv.setImageBitmap(bm); 
    }catch (Exception e) { 
     // TODO: handle exception 
     e.printStackTrace(); 
    } 
    dialog.show(); 
} 

我ArrayAdapter的列表視圖

class IconicAdapter extends ArrayAdapter<String>{ 

     IconicAdapter() { 
      super(A_Test4Activity.this, R.layout.row, R.id.label, book_fileName_list); 
      } 
     public View getView(int position, View convertView, 
       ViewGroup parent) { 
//    String[] items = book_fileName_list.toArray(new String[book_fileName_list.size()]); 
       View row = super.getView(position, convertView, parent); 
       ImageView icon=(ImageView)row.findViewById(R.id.icon); 
       TextView author = (TextView)row.findViewById(R.id.book_Author); 
       TextView bookTitle = (TextView)row.findViewById(R.id.Book_Title); 

       icon.setImageBitmap(bm_List.get(position)); 
       bookTitle.setText(book_title_list.get(position)); 
       author.setText(List_Author.get(position)); 


       return(row); 
       } 
    } 

我的自定義Dialog.xml

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

     <ImageView 
      android:id="@+id/dialog_image" 
      android:layout_width="300px" 
      android:layout_height="300px" 
      android:src="@drawable/temp_book" 
       /> 
    <ScrollView 
     android:id="@+id/scroller" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     > 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
     <TextView android:id="@+id/data1" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#FFF" 
       android:textSize="10sp" 
       android:text="Data1" 
       /> 
     </LinearLayout> 
    </ScrollView> 

     <Button 
      android:id = "@+id/confirm" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="CONFIRM"/> 
     <Button 
      android:id = "@+id/close" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="CLOSE"/> 

</LinearLayout> 

忘了把我的logcat錯誤

02-23 16:00:02.862: W/TextLayoutCache(2286): computeValuesWithHarfbuzz -- need to force to single run 

02-23 16:00:04.495: W/System.err(2286): java.lang.NullPointerException 

02-23 16:00:04.495: W/System.err(2286):  at test.list.A_Test4Activity.onListItemClick(A_Test4Activity.java:328) 

02-23 16:00:04.495: W/System.err(2286):  at android.app.ListActivity$2.onItemClick(ListActivity.java:319) 

02-23 16:00:04.495: W/System.err(2286):  at android.widget.AdapterView.performItemClick(AdapterView.java:292) 

02-23 16:00:04.495: W/System.err(2286):  at android.widget.AbsListView.performItemClick(AbsListView.java:1058) 

02-23 16:00:04.495: W/System.err(2286):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514) 

02-23 16:00:04.495: W/System.err(2286):  at android.widget.AbsListView$1.run(AbsListView.java:3168) 


02-23 16:00:04.495: W/System.err(2286):  at android.os.Handler.handleCallback(Handler.java:605) 

02-23 16:00:04.495: W/System.err(2286):  at android.os.Handler.dispatchMessage(Handler.java:92) 

02-23 16:00:04.495: W/System.err(2286):  at android.os.Looper.loop(Looper.java:137) 

02-23 16:00:04.495: W/System.err(2286):  at android.app.ActivityThread.main(ActivityThread.java:4340) 

02-23 16:00:04.495: W/System.err(2286):  at java.lang.reflect.Method.invokeNative(Native Method) 

02-23 16:00:04.495: W/System.err(2286):  at java.lang.reflect.Method.invoke(Method.java:511) 

02-23 16:00:04.495: W/System.err(2286):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 

02-23 16:00:04.503: W/System.err(2286):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
02-23 16:00:04.503: W/System.err(2286):  at dalvik.system.NativeStart.main(Native Method) 

回答

0

使用自定義警告對話框中爲我工作。由於它的dev最後一行指出「使用AlertDialog您的自定義佈局,您可以利用內置的AlertDialog功能,比如管理按鈕,選擇列表,一個標題,圖標等。優勢」。 因爲我正在做一個自定義對話框,而不需要管理多個對話框,所以這對我有用。

0

你應該叫活動的ShowDialog(INT)。 int值標識一種對話框。你必須實現這個回調並在這個方法中返回一個對話對象(你的對話框)。

你有例子: http://developer.android.com/guide/topics/ui/dialogs.html

 protected Dialog onCreateDialog(int id) { 
     case MY_DIALOG: 
      Dialog dialog = new Dialog(A_Test4Activity.this); 
          dialog.setContentView(R.layout.custom_dialog); 
          dialog.setTitle("Title"); 
     break; 
     default: 
      dialog = null; 
     } 
     return dialog; 
    } 

然後,撥打

的ShowDialog(MY_DIALOG);
您的活動

+0

我相信,雖然,使用onCreateDialog是,如果你有多個對話。看看這個例子,它顯示了兩個可能的對話框,使用整數來區分它們。糾正我,如果我錯了。 – wesdfgfgd 2012-02-23 21:46:36

+0

我只有一個展示。只是它即使在圖像/圖像存在的情況下也會對圖像賦予空值。 – wesdfgfgd 2012-02-23 21:51:15

相關問題