0

我想要我的应用程序可以同时下载多个文件并在通知区域显示下载每个文件的过程我该怎么做?现在我下载文件时只能显示 1 个进程栏。这里文件 notification_progress_layout.xml

<?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>

和通知文件

        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);
4

1 回答 1

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);

使用正确的值更改每次下载的进度条值。

于 2012-11-30T08:41:39.693 回答