在视图页面中没有在andorid中显示图像滑块的图像

时间:2016-05-06 06:27:59

标签: android android-layout android-fragments android-studio android-imageview

在View Pager中没有显示图像,我从JSON获取了图像URL,但是Image Loader显示图像时出现了一些错误。

MODEL:

public class ZoomimageModel {
    private int id;
    private String imageUrl;
    public void ZoomimageModel(String imageUrl) {
        this.imageUrl=imageUrl;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getId() {
        return id;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }
}

查看寻呼机适配器:

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.journaldev.navigationdrawer.Model.ListModel;
import com.journaldev.navigationdrawer.Model.ZoomimageModel;
import com.journaldev.navigationdrawer.R;
import com.journaldev.navigationdrawer.app.YelloPage;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;

/**
 * Created by admin on 5/5/2016.
 */
public class ZoomAdapter extends PagerAdapter
{
    LayoutInflater inflator;
    ImageView imgDisplay;
    Context context;
    ArrayList<ZoomimageModel> slideShowImages;
    DisplayImageOptions options;

    public ZoomAdapter(ArrayList<ZoomimageModel> slideShowImages,Context context)
    {
        this.context=context;
        this.slideShowImages =slideShowImages;
        options = new DisplayImageOptions.Builder()
                .showStubImage(R.drawable.b2)
                .showImageForEmptyUri(R.drawable.b2)
                .showImageOnFail(R.drawable.b2)
                .build();
    }
    @Override
    public int getCount()
    {
        return slideShowImages.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((ImageView) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View viewLayout = inflator.inflate(R.layout.productzoomrow, container,
                false);
        imgDisplay = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
//  BitmapFactory.Options options = new BitmapFactory.Options();
//  options.inPreferredConfig = Bitmap.Config.ARGB_8888;
//  Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);
//  imgDisplay.setImageBitmap(bitmap);
//

        System.out.println("ImageUrl---------------------"+slideShowImages.get(position));



        YelloPage.imageLoader.displayImage(String.valueOf(slideShowImages.get(position)), imgDisplay, options);
        ((ViewPager) container).addView(imgDisplay, 0);
        return imgDisplay;

    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        ((ViewPager) container).removeView((ImageView) object);
    }
}

CODE

public class Zoomproduct_Activity extends AppCompatActivity {
    private Toolbar toolbar;
    LinearLayout buynow, cart;
    private Button cartbtn, buybtn;
    private ProgressDialog pDialog;
    DisplayImageOptions options;
    String productpath;
    private static String TAG = Zoomproduct_Activity.class.getSimpleName();
    private final static String DATA = "data";
    private final static String PRODUCT_IMAGES = "product_images";
    private ImageView firstimages, multipleimages;
    private TextView offerpercentage;
    String singleproduct;
    LinearLayout horizontalimage;
    int selectedimageviewpos = 0;
    int positionOfDeviceImage;
    ImageView[] ii;
    String offpercent;
    HashMap < String, String > resultp = new HashMap < String, String > ();
    JSONObject pimages;
    String images;
    String offerprice;
    String original;
    JSONArray multipleimage;
    JSONObject alertObj;
    int startdate;
    int endate2;
    FrameLayout frame;
    int currentindex;
    ViewPager viewPager;
    ZoomAdapter adapter;
    String singlepro, multipleimg, productpaths, sellers;
    ArrayList < ZoomimageModel > imgs;
    // ArrayList<HashMap<String, String>> adlist
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoomproduct_);
        options = new DisplayImageOptions.Builder()
            .showStubImage(R.drawable.b2)
            .showImageForEmptyUri(R.drawable.b2)
            .showImageOnFail(R.drawable.b2)
            .build();


        /********************  this is for single page product ***********************/

        Intent singleproductpage = getIntent();
        singlepro = singleproductpage.getStringExtra("currentinedx");
        Intent multipleimages = getIntent();
        multipleimg = multipleimages.getStringExtra("multipleimages");
        Intent productpath = getIntent();
        productpaths = productpath.getStringExtra("productpath");
        Intent seller = getIntent();
        sellers = seller.getStringExtra("sellerid");
        //  pDialog = new ProgressDialog(Zoomproduct_Activity.this);
        //   pDialog.setMessage("Please wait...");
        //   pDialog.setCancelable(false);
        singleproduct();

        viewPager = (ViewPager) findViewById(R.id.pager);
        // Pass results to ViewPagerAdapter Class
        adapter = new ZoomAdapter(imgs, Zoomproduct_Activity.this);
        // Binds the Adapter to the ViewPager
        viewPager.setAdapter(adapter);


    }




    public void singleproduct() {


        String productpath = productpaths;
        String sid = sellers;
        String cindex = singlepro;
        int cindexs = Integer.parseInt(cindex);
        String multiimg = multipleimg;
        JSONArray multipleimage = null;
        try {
            multipleimage = new JSONArray(multiimg);



            horizontalimage = (LinearLayout) findViewById(R.id.gallery);
            // final RelativeLayout r1=(RelativeLayout)findViewById(R.id.relative_border);
            //   frame=(FrameLayout)findViewById(R.id.framelayout);
            ii = new ImageView[multipleimage.length()];
            if (multipleimage.length() > 0) {
                for (int j = 0; j < multipleimage.length(); j++) {
                    pimages = multipleimage.getJSONObject(j);
                    JSONObject oneimage = multipleimage.getJSONObject(j);

                    multipleimages = (ImageView) findViewById(R.id.singleimage);
                    ii[j] = new ImageView(Zoomproduct_Activity.this);
                    ii[j].setScaleType(ImageView.ScaleType.FIT_CENTER);
                    LinearLayout.LayoutParams image = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                    image.width = 100;
                    image.height = 100;
                    image.setMargins(10, 0, 0, 0);
                    ii[j].setPadding(10, 10, 10, 10);
                    ZoomimageModel zoom = new ZoomimageModel();
                    String oneimg = oneimage.getString("original_res");
                    String singleiamges = productpath + sid + '/' + oneimg;

                    imgs = new ArrayList < ZoomimageModel > ();
                    final String multimgs = pimages.getString("original_res");
                    zoom.setImageUrl(singleiamges);
                    imgs.add(zoom);




                    String[] img2 = multimgs.split("\\.");
                    String imagone = productpath + sid + '/' + img2[0] + '(' + '2' + '0' + '0' + ')' + '.' + img2[1];

                    // displayimages=productpath + alertObj.getString("seller_id")+  '/' + multimgs[];
                    YelloPage.imageLoader.displayImage(imagone, ii[j], options);
                    //  YelloPage.imageLoader.displayImage(singleiamges, multipleimages, options);
                    ii[j].setLayoutParams(image);
                    horizontalimage.addView(ii[j]);



                }



            } else {

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    private void showpDialog() {
        if (!pDialog.isShowing())
            pDialog.show();
    }

    private void hidepDialog() {
        if (pDialog.isShowing())
            pDialog.dismiss();
    }
}

Logcat错误:

  05 - 06 02: 22: 35.850 3760 - 3760 / com.journaldev.navigationdrawer I / System.out: ImageUrl-- -- -- -- -- -- -- -- -- -- - com.journaldev.navigationdrawer.Model.ZoomimageModel @2471087
05 - 06 02: 22: 35.854 3760 - 4038 / com.journaldev.navigationdrawer E / ImageLoader: UIL doesn 't support scheme(protocol) by default [com.journaldev.navigationdrawer.Model.ZoomimageModel@2471087]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
java.lang.UnsupportedOperationException: UIL doesn 't support scheme(protocol) by default [com.journaldev.navigationdrawer.Model.ZoomimageModel@2471087]. You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromOtherSource(BaseImageDownloader.java: 280)
at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java: 99)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(BaseImageDecoder.java: 98)
at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java: 74)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java: 265)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java: 238)
at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java: 136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 587)
at java.lang.Thread.run(Thread.java: 818)
05 - 06 02: 22: 35.897 3760 - 3915 / com.journaldev.navigationdrawer W / EGL_emulation: eglSurfaceAttrib not implemented
05 - 06 02: 22: 35.897 3760 - 3915 / com.journaldev.navigationdrawer W / OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xdf3db200, error = EGL_SUCCESS

我在Image Loader中遇到错误,任何一个帮助解决我的问题。 提前谢谢。

1 个答案:

答案 0 :(得分:1)

actions: {
  toggle (title, event) {
    // TODO: use title 
    let element = Ember.$(event.target);
    element.toggleClass("active");

    return false;
  }
}

它返回slideShowImages.get(position) 而不是imageUrl