2012-11-30 21 views
0

我想我的應用程序,可以同時下載多個文件,並顯示在通知區域下載每個文件的過程 我該怎麼做?現在我只能顯示1個進程欄當我下載文件。 這裏提交notification_progress_layout.xmlandroid通知擴大視圖與多個進程欄

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="5dp"> 
<ImageView android:id="@+id/status_icon" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_marginRight="10dp" 
    android:src="@drawable/icon_download1"/> 

<RelativeLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_toRightOf="@id/status_icon"> 

    <TextView android:id="@+id/status_text" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     /> 
    <ProgressBar android:id="@+id/status_progress" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/status_text" 
     android:indeterminate="false" 
     android:indeterminateOnly="false" 
     style="?android:attr/progressBarStyleHorizontal" /> 


</RelativeLayout> 

和nofitication文件

 Intent notificationIntent = new Intent(); 
     PendingIntent contentIntent = PendingIntent.getActivity(activity, 0, notificationIntent, 0); 
     notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); 
     notification = new Notification(R.drawable.icon_download1, "Downloading...", System.currentTimeMillis()); 

     contentView = new RemoteViews(activity.getPackageName(), R.layout.notification_progress_layout); 
     contentView.setProgressBar(R.id.status_progress, 100, 0, false);   
     contentView.setTextViewText(R.id.status_text,"Downloading..."); 

     notification.flags = notification.flags| Notification.FLAG_ONGOING_EVENT; 
     notification.contentView = contentView;   
     notification.contentIntent = contentIntent; 

     notificationManager.notify(NOTIFICATION_ID,notification); 
+0

我認爲它只適用於4.1中引入的消耗性通知。搜索BigContentView以獲取有關如何執行此操作的示例。 – Teovald

回答

0

這樣做:

  1. 創建一個LinearLayout內默認的XML。
  2. 裏面創建另一個佈局,其中ProgressBar
  3. 使用下面的代碼。

代碼:

contentView = new RemoteViews(activity.getPackageName(), R.layout.notification_progress_main); 
for (i=0; i<downloads.length;i++){ 
    contentView2 = new RemoteViews(activity.getPackageName(), R.layout.notification_progress_layout); 
    contentView2.setProgressBar(R.id.status_progress, 100, 0, false); 
    contentView.addView(R.layout.linearid, contentView2); 

} 
notification.contentView = contentView; 
notificationManager.notify(NOTIFICATION_ID,notification); 

更改進度值與每個下載正確的價值觀。

+0

如果我這樣做,那麼我有不同的通知,並且每個通知都有一個進程欄。如果我將多個進程欄放入一個通知中,是否有可能? – chinh

+0

回答編輯:) – jaumard

+0

謝謝,當下載完成後,我想刪除每個進程欄。我看到RemoteView沒有刪除子佈局功能。如何才能做到這一點 – chinh