2013-02-22 85 views
0

我在Listview中通過運行背面任務逐個加載圖像。我正在運行進度條,直到它完全加載。當圖像開始加載時,進度不會改變。我想要在圖像加載時更改進度條的位置。如何做?我究竟做錯了什麼?如何在List視圖中加載圖像時移動進度條的位置

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relaGrid" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <include 
     android:id="@+id/Master" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/activity_master_page" /> 

    <ListView 
     android:id="@+id/ItemView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@+id/Master" > 
    </ListView> 

<ProgressBar 
     android:id="@+id/ItemsProgressBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Master" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 

添加用於加載圖像的代碼

私有類testAynscTask延伸的AsyncTask {

@Override 
    protected void onPreExecute() { 
     TheProgressBarG = (ProgressBar) findViewById(R.id.ItemsProgressBar); 
     TheProgressBarG.setVisibility(View.VISIBLE); 
    } 

    protected Void doInBackground(Void... ParamsP) { 

     try { 
      POSManager aPOSManagerL = new POSManager(); 
      ListCriteria aListCriteriaL = new ListCriteria(); 
      ObjectInformation zItemInfoL = new ObjectInformation(); 
      CategoryItemListG = new ObjectList(); 
      //Get CategoryId 
      String zCategoryIdL = GetCategoryId(); 

      aListCriteriaL.SearchConditionsM.AddSearchConditionWithValue("Item_Category.Id", zCategoryIdL); 
      Gson gsonBuilderL = new GsonBuilder().serializeNulls().create(); 
      String zListCriteriaL = gsonBuilderL.toJson(aListCriteriaL); 

      //Get Category Items List 
      aPOSManagerL.GetCategoryItems(HttpUtil.SessionKeyM,zListCriteriaL); 

      DisplayMetrics zDisplayMetricsL = new DisplayMetrics(); 
      getWindowManager().getDefaultDisplay().getMetrics(zDisplayMetricsL); 
      int nPreviewSizeL = zDisplayMetricsL.widthPixels/3; 

      ObjectList zItemListL = HttpUtil.CategoryItemListM; 

      for (int countL = 0; countL < zItemListL.GetLength(); countL++) { 

       zItemInfoL = (ObjectInformation) zItemListL.GetObject(countL); 
       String zItemIdL = (String) zItemInfoL.GetValue("ID"); 
       //Get Item Image 
       aPOSManagerL.GetCategoryItemImage(HttpUtil.SessionKeyM,zItemIdL, nPreviewSizeL); 
       zItemInfoL.SetValue("aPictureByteArrayP",HttpUtil.CategoryItemImageBytesM); 
       CategoryItemListG.Add(zItemInfoL); 
       publishProgress(countL); 
      } 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return null; 
    } 

    protected void onProgressUpdate(Integer... PositionP) { 

     ListView TheItemListViewL=(ListView) findViewById(R.id.ItemView); 
     TheItemListViewL.setAdapter(anImageAdapterG); 
     super.onProgressUpdate(PositionP); 
    } 

    @Override 
    protected void onPostExecute(Void ResultP) { 
     super.onPostExecute(ResultP); 
     TheProgressBarG.setVisibility(View.INVISIBLE); 
     anImageAdapterG.notifyDataSetChanged(); 

    } 
} 

公共類ImageAdapter延伸BaseAdapter { 私有上下文mContextL;

public ImageAdapter(Context contextP) { 
     mContextL = contextP; 
    } 

    public int getCount() { 
     return CategoryItemListG.GetLength(); 
     // return mImageIds.length; 
    } 

    public Object getItem(int PositionP) { 
     return PositionP; 
    } 

    public long getItemId(int PositionP) { 
     return PositionP; 
    } 

    public View getView(int PositionP, View ConvertViewP, ViewGroup ParentP) { 

     ObjectInformation zItemInfoL = (ObjectInformation)CategoryItemListG.GetObject(PositionP); 
     String zItemNameL = (String)zItemInfoL.GetValue("ITEMNAME"); 
     String zItemPriceL = (String)zItemInfoL.GetValue("SalesPrice"); 
     String zItemImageBytesL = (String)zItemInfoL.GetValue("aPictureByteArrayP"); 

     Bitmap ItemImageBitMapL =GetItemImageBitMap(zItemImageBytesL); 

     RelativeLayout TheRelativelayoutL = new RelativeLayout(getApplicationContext()); 

     ImageView TheItemImageL = new ImageView(mContextL); 
     TheItemImageL.setImageBitmap(ItemImageBitMapL); 
     TheItemImageL.setScaleType(ImageView.ScaleType.FIT_XY); 
     TheItemImageL.setLayoutParams(new ListView.LayoutParams(100,100)); 
     TheItemImageL.setPadding(1, 0, 0, 0); 
     TheItemImageL.setId(1); 

     TextView tvItemNameL = new TextView(mContextL); 
     tvItemNameL.setText(zItemNameL); 
     tvItemNameL.setGravity(Gravity.CENTER); 
     tvItemNameL.setTextSize(10); 
     tvItemNameL.setTextColor(Color.parseColor("#000000")); 
     tvItemNameL.setPadding(15, 0, 0, 0); 
     tvItemNameL.setId(2); 

     TextView tvItemPriceL = new TextView(mContextL); 
     tvItemPriceL.setText("Rs. "+zItemPriceL); 
     tvItemPriceL.setGravity(Gravity.CENTER); 
     tvItemPriceL.setTextSize(10); 
     tvItemPriceL.setTextColor(Color.parseColor("#A30000")); 
     tvItemPriceL.setId(3); 
     tvItemPriceL.setPadding(15, 0, 0, 20); 

     TheRelativelayoutL.addView(TheItemImageL); 

     RelativeLayout.LayoutParams zRelativeLayoutParamsL = new RelativeLayout.LayoutParams((RelativeLayout.LayoutParams.WRAP_CONTENT),(RelativeLayout.LayoutParams.WRAP_CONTENT)); 
     zRelativeLayoutParamsL.addRule(RelativeLayout.RIGHT_OF,1); 
     zRelativeLayoutParamsL.addRule(RelativeLayout.CENTER_IN_PARENT); 

     TheRelativelayoutL.addView(tvItemNameL, zRelativeLayoutParamsL); 

     zRelativeLayoutParamsL = new RelativeLayout.LayoutParams((RelativeLayout.LayoutParams.WRAP_CONTENT),(RelativeLayout.LayoutParams.WRAP_CONTENT)); 
     zRelativeLayoutParamsL.addRule(RelativeLayout.RIGHT_OF,1); 
     zRelativeLayoutParamsL.addRule(RelativeLayout.BELOW,2); 
     zRelativeLayoutParamsL.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 

     TheRelativelayoutL.addView(tvItemPriceL, zRelativeLayoutParamsL); 

     return TheRelativelayoutL; 
    } 
+0

這只是事物的佈局,這裏是背後的邏輯.. – nsthethunderbolt 2013-02-22 06:14:04

+0

請添加在你的問題你的代碼。 – NaviRamyle 2013-02-22 06:37:53

回答

0
I made the below changes to the UI and it works fine for me 

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

    <include 
     android:id="@+id/Master" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     layout="@layout/activity_master_page" /> 

    <ListView 
     android:id="@+id/ItemView" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/Master" > 
    </ListView> 

    <ProgressBar 
     android:id="@+id/ItemsProgressBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/ItemView" 
     android:layout_centerHorizontal="true" /> 


</RelativeLayout> 
相關問題