0

Integrated images displaying in the form of list,gallery,grid view by using this

https://github.com/nostra13/Android-Universal-Image-Loader

but have to integrate the images in the form one by one image from server..Please suggest me..Please give me sample example.

public class ParsingActivity extends Activity {
ParsingPojo data_pojo;
ArrayList<ParsingPojo> dataArray;
ListView diagnoList;
ImageView dataWithImage;
private EditText editTextInput;
ProgressDialog mdialog;
ProgressDialog progressDialog;
private Handler handler;
private Handler messageHandler;
private ProgressDialog progress;
private Context context;

String resp, url;
protected DisplayImageOptions displayImage;
protected ImageLoader imageLoader = ImageLoader.getInstance();

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cat);

    dataWithImage = (ImageView) findViewById(R.id.stack);


    displayImage = new DisplayImageOptions.Builder()
    .showImageForEmptyUri(R.drawable.ic_launcher)
    .showStubImage(R.drawable.ic_launcher)
    .cacheInMemory()
        .cacheOnDisc()
        .bitmapConfig(Bitmap.Config.RGB_565)
        .build();
     imageLoader.init(ImageLoaderConfiguration
    .createDefault(ParsingActivity.this));
     new Task().execute();

}




protected void search() {
    // TODO Auto-generated method stub

}




static class ViewHolder {

    TextView coverTitle, content, image;
    ImageView images;
}

class Task extends AsyncTask<Void, Void, Void> {

    ProgressDialog pd;

    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pd = ProgressDialog.show(ParsingActivity.this, "please wait..",
                "loading data");
    }

    protected Void doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        try {
            url = "your url";
            resp = CustomHttpClient.executeHttpGet(url);
            dataArray = new ArrayList<ParsingPojo>();
            JSONArray data = new JSONArray(resp);
            for (int i = 0; i < data.length(); i++) {
                data_pojo = new ParsingPojo();
                JSONObject jobj = data.getJSONObject(i);
                JSONObject innerObject = jobj.getJSONObject("first_post");
                JSONArray imageArray = innerObject.getJSONArray("files");
                JSONArray imageOk = imageArray.getJSONArray(0);
                data_pojo.setImage("ur url"
                        + imageOk.getString(0));
                data_pojo.setContent(innerObject.getString("content"));
                data_pojo.setConv_title(jobj.getString("conv_title"));
                dataArray.add(data_pojo);
            }

            /*
             * JSONObject jobj = new JSONObject(resp); JSONArray jarray =
             * jobj.getJSONArray("diagnoresultpojo"); // JSONArray jarray =
             * new JSONArray("diagnoresultpojo");
             * 
             * dataArray = new ArrayList<ParsingPojo>(); for (int i = 0; i <
             * jarray.length(); i++) { data_pojo = new ParsingPojo();
             * JSONObject insideArrayJobj = jarray.getJSONObject(i);
             * data_pojo.setName(insideArrayJobj.getString("name"));
             * data_pojo.setMobile(insideArrayJobj.getString("mobile"));
             * data_pojo.setImage_url(insideArrayJobj
             * .getString("image_url"));
             * data_pojo.setEmail(insideArrayJobj.getString("email"));
             * data_pojo.setAddress(insideArrayJobj.getString("address"));
             * dataArray.add(data_pojo); } Log.d("array size",
             * dataArray.size() + "");
             */
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }



    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        pd.dismiss();
        if (dataArray != null) {
            dataWithImage.setAdapter(new Adapter());
        }

    }

}

public class Adapter extends BaseAdapter {

    public int getCount() {
        // TODO Auto-generated method stub
        if (dataArray.size() != 0) {
            return dataArray.size();
        } else
            return 0;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        View show = arg1;
        ViewHolder holder;
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (show == null) {
            holder = new ViewHolder();
            show = inflater.inflate(R.layout.gallery_image, null);
            holder.coverTitle = (TextView) show.findViewById(R.id.name);
            // holder.content = (TextView) show.findViewById(R.id.content);
            // holder.image = (TextView) show.findViewById(R.id.image);
            holder.images = (ImageView) show.findViewById(R.id.image);
            /*
             * holder.mobile = (TextView) show.findViewById(R.id.mobile);
             * holder.email = (TextView) show.findViewById(R.id.email);
             * holder.address = (TextView) show.findViewById(R.id.address);
             * holder.image = (TextView) show.findViewById(R.id.image);
             */
        } else {
            holder = (ViewHolder) show.getTag();
        }
        holder.coverTitle.setText(dataArray.get(arg0).getConv_title());
        // holder.content.setText(dataArray.get(arg0).getContent());
        // holder.image.setText(dataArray.get(arg0).getImage());
        imageLoader.displayImage(dataArray.get(arg0).getImage(),
                holder.images, displayImage);
        holder.images.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent content = new Intent(ParsingActivity.this,
                        Content.class);
                content.putExtra("data", dataArray.get(arg0).getContent());
                content.putExtra("title", dataArray.get(arg0)
                        .getConv_title());

                startActivity(content);
            }
        });

        /*
         * holder.mobile.setText(dataArray.get(arg0).getMobile());
         * holder.email.setText(dataArray.get(arg0).getEmail());
         * holder.address.setText(dataArray.get(arg0).getAddress());
         * holder.image.setText(dataArray.get(arg0).getImage_url());
         */
        show.setTag(holder);
        return show;
    }



}

}

Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
Sandy
  • 1
  • 1
  • 5

1 Answers1

0

Here is the sample which you are expecting. In this example list view images are get loaded from server urls(From Service Dynamically)

have a look at this. http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ hope this helps you.

EDIT Here is the code which you want.

package com.sample.view;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class Test3 extends Activity {

    ImageView imageview1;
    Button button1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);     
        imageview1=(ImageView)findViewById(R.id.imageView1);        
        mHandler = new Handler();       

                imageview1.setVisibility(View.VISIBLE);     

                 startPlay();
    }

    int mThumbIds[]={R.drawable.ic_launcher,R.drawable.home,R.drawable.green        
    };
     int i =0;    
        private Handler mHandler;
     private void startPlay(){

            final Timer timer = new Timer();

            timer.scheduleAtFixedRate(new TimerTask() {

            public void run() {

                Log.i("Test", "Sample= " +i);                   
                    play(i);
                    if(i==2){

                        timer.cancel();
                        startPlay(); //for continuous play. infinite play 
                        i=0;// resetting the values
                    }
                    else{
                    i++;
                    }

            }

            }, 1800, 1800); // here is the duration whcih you want to change the images. 

        }
        private void play(final int round){
            mHandler.post(new Runnable(){
                public void run(){

                    imageview1.setImageResource(mThumbIds[round]);
                    Animation hyperspaceJump1 = AnimationUtils.loadAnimation(Test3.this,android.R.anim.fade_in);                
                    imageview1.startAnimation(hyperspaceJump1); 
                }
            });
        }

}
itsrajesh4uguys
  • 4,610
  • 3
  • 20
  • 31
  • I dont want images that are displayed in the form of any view just i want there is only one imageview, in that display images in the form one after one like flip animation effect,Please suggest some other way.. – Sandy Jun 07 '13 at 05:58
  • Viewpager is like gallery images,but i need images one by one like http://news5.in/n5/ only take any one category... – Sandy Jun 07 '13 at 06:25
  • @Sandy yes one image displayed on you swipe right to left display another image . you can use view pager. if you use gridview it will look like gallery. – Raghunandan Jun 07 '13 at 06:26
  • @Sandy check the link. http://tinypic.com/view.php?pic=f0z3ht&s=5. display one image and swipe right to left will display another image and so on. looking for this? need a sample let me know – Raghunandan Jun 07 '13 at 06:30
  • you can use stackviewer for that else by using timer you can change the images.. periodically.. do you want timer code ? – itsrajesh4uguys Jun 07 '13 at 06:37
  • @Sandy pls state clearly what you need?. images in listview? images in gridview? images in viewpager? this "in the form one by one image from server" is very unclear – Raghunandan Jun 07 '13 at 06:40
  • hi here is the documentation about stackview http://developer.android.com/guide/topics/appwidgets/index.html#collection_sample – itsrajesh4uguys Jun 07 '13 at 06:41
  • images in flip view...like this website..http://news5.in/n5/ take only single category that effect... – Sandy Jun 07 '13 at 06:41
  • hi here is the nice tutorial for that. http://www.thaicreate.com/mobile/android-stackview.html – itsrajesh4uguys Jun 07 '13 at 06:45
  • yeah that is also more or less having the same animation. you can use that .. you can automatically move the images by using stack view. – itsrajesh4uguys Jun 07 '13 at 06:47
  • Hi can please go through that url which i have posted i need that effect i am calling images from server..Please help me.. – Sandy Jun 07 '13 at 06:47
  • @rajesh hi rajesh thanks alot 4 ur answer but please go through my code i need to display the data from the server please help me...please edit that code.. – Sandy Jun 07 '13 at 11:09