2

I am working on ad banner and i want to flip image after 4 sec in the banner layout so for that i am using viewflipper. I want to show images taken from web service so i am parsing image from web service and create list of it but when pass that list item using for loop to viewflipper it is showing only one image and list have two items. Can anyone help me to figure out my mistake.

View flipper method..

    public void flipperImages(String image){
    ImageView imageView = new ImageView(this);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageView.setLayoutParams(params);
    Log.e("image_product", image);
    if (image.equals("0")) {
        imageView.setBackgroundResource(R.drawable.placeholder_rec);
    } else {
        Picasso.with(this).load(image).error(R.drawable.placeholder_rec).placeholder(R.drawable.placeholder_rec).into(imageView);
    }


    v_flipper.addView(imageView);
    v_flipper.setFlipInterval(4000);
    v_flipper.setAutoStart(true);

    v_flipper.setInAnimation(this, android.R.anim.slide_in_left);
    v_flipper.setOutAnimation(this, android.R.anim.slide_out_right);

}

Api call and flipperImages() call...

      private void categoryListApi() {

    if (NetworkUtil.isNetworkAvailable(this)) {

        loader.setVisibility(View.VISIBLE);

        Api api = ApiClient.getClient().create( Api.class );
        Call<ResponseBody> call = api.getCatList("1");

        call.enqueue( new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    loader.setVisibility(View.GONE);
                    String JSON_STRING = response.body().string();
                    JSONObject jsonRootObject = new JSONObject( JSON_STRING );

                    String status = jsonRootObject.getString( "status" );
                    String message = jsonRootObject.getString( "message" );

                    if (status.equals( "1" ))
                    {
                        JSONArray jsonArrayBanner = jsonRootObject.getJSONArray( "banner" );
                        for (int i=0; i<jsonArrayBanner.length(); i++)
                        {
                            JSONObject objectData = jsonArrayBanner.getJSONObject(i);
                            String bannerUrl = objectData.getString( "img" );
                            bannerList.add( bannerUrl );
                        }
                        Log.e("banner", bannerList.toString());
                        for (int i=0; i<bannerList.size(); i++)
                        {
                            flipperImages(bannerList.get(i));

                        }

                    } else {
                        loader.setVisibility(View.GONE);
                        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
                    }

                } catch (Exception e) {
                    Log.e( "ErrorProfile" , e.getMessage());
                    loader.setVisibility(View.GONE);
                    popUpDialog();
                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                loader.setVisibility(View.GONE);
                //Toast.makeText( getApplicationContext(), "Failed " + t, Toast.LENGTH_LONG ).show();
            }
        } );
    }
    else {
        popUpDialogInternet();
    }
}

0 Answers0