0

バックグラウンドでタスクを実行して、リストビューで画像を1つずつロードしています。完全にロードされるまで進行状況バーを実行しています。画像のロードが開始されても進行状況の位置は変わりません。画像が読み込まれるときに変更されます。どうすればいいですか? 私は何を間違っていますか?

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

    }
}

public class ImageAdapter extends 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;
    }
4

1 に答える 1

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>
于 2013-02-26T04:56:49.550 に答える