0

使用此功能以列表,图库,网格视图的形式集成图像显示

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

但必须将来自服务器的图像一张一张地整合在一起..请建议我..请给我示例。

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;
    }



}

}

4

1 回答 1

0

这是您期望的示例。在此示例中,列表视图图像是从服务器 url 加载的(从服务动态)

看看这个。http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ 希望这对您有所帮助。

编辑 这是你想要的代码。

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

}
于 2013-06-07T05:52:15.303 回答