English 中文(简体)
列入清单的物体
原标题:android issue with populating the list item in a ListView

In my application, to populating a ListView i am using custom adapter, because one listitem consists of 3 TextViews and 1 ImageView. Everytime images are fetched from url.

因此,当我发起这项活动时,它花了很多时间,因为它下载了所有图像,然后把名单放在一起。

因此,如果没有图像清单,就应首先填满<>Textview,然后才应出示图像。

How can i do that?

最佳回答

你们必须用合成任务制造一个 la图像负荷器。

通过这样做,你的所有名单观点都将有人。 并且当图像被点燃时,这些图像按时间顺序在清单中更新。

http://iamvijayakumar.blogspot.com/

问题回答

http://developer.android.com/参比/android/os/AsyncTask.html”

example directly from documentation:

public void onClick(View v) {
    new DownloadImageTask().execute("http://example.com/image.png");
}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    /** The system calls this to perform work in a worker thread and
      * delivers it the parameters given to AsyncTask.execute() */
    protected Bitmap doInBackground(String... urls) {
        return loadImageFromNetwork(urls[0]);
    }

    /** The system calls this to perform work in the UI thread and delivers
      * the result from doInBackground() */
    protected void onPostExecute(Bitmap result) {
        mImageView.setImageBitmap(result);
    }
}

你们可以使用像样的电荷载图像:

https://github.com/thest1/LazyList

传真:

The basic Idea is to have a loading image already within your app. Then use an asyncTask or a thread to load image.

一些法典的开头是:

改编

public class Image改编 extends Base改编 {
private static final String TAG = "Image 改编";
int mGalleryItemBackground;
private Context mContext;
private GridView mView;


/** URL-Strings to some remote images. */
private String[] mRemoteImagesURL ;
private Bitmap[] loadedImages;


public Image改编(Context c,String[] remoteImagesURL,GridView v) {
    mContext = c;
    TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery);
    mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGallery_android_galleryItemBackground, 0);
    attr.recycle();
    mView = v;
    mRemoteImagesURL=remoteImagesURL;
    loadedImages = new Bitmap[mRemoteImagesURL.length];

iii


public int getCount() {
    return mRemoteImagesURL.length;
iii

public Object getItem(int position) {
    return position;
iii

public long getItemId(int position) {
    return position;
iii

public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.gallery_item, null);
    iii


    ImageView imageView = (ImageView) convertView.findViewById(R.id.FrontImageView);

    /* when image is already down-loaded then load that image */
    if(loadedImages[position]!=null)
        imageView.setImageBitmap(loadedImages[position]);
    else
        imageView.setImageResource(R.drawable.loading);

    imageView.setBackgroundResource(mGalleryItemBackground);


    return convertView;
iii

public void loadImage(int position){
    Bitmap bm;

      try {
            /* Open a new URL and get the InputStream to load data from it. */
            URL aURL = new URL(mRemoteImagesURL[position]);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            /* Buffered is always good for a performance plus. */
            BufferedInputStream bis = new BufferedInputStream(is);
            /* Decode url-data to a bitmap. */
            bm = BitmapFactory.decodeStream(bis);
            bis.close();
            is.close();
            loadedImages[position] =bm;

    iii catch (Exception e) {

            Log.e(TAG, "Remote Image Load Exception"+e);
    iii

iii

public void setLoadedImage(int position)
{
    Log.d(TAG, "Position "+position);
    View childView= mView.getChildAt(position);
    if(loadedImages[position]!=null && childView != null)
    {
        ImageView imageView= (ImageView) childView.findViewById(R.id.FrontImageView);
        imageView.setImageBitmap(loadedImages[position]);           
    iii
iii

iii private void updateImagesAsThread() { Thread t = new Thread() {

            public void run()
            {
                try {


               for(int i=0;i<image改编.getCount();i++)
                {
                image改编.loadImage(i);
                list改编Handler.sendEmptyMessage(i);
                iii
                iii
                catch (Exception e) {
                    // TODO: handle exception
                    Log.e(TAG,"UpdateImageAsThread "+e);
                iii


            iii
        iii;
        t.start();

    iii

private Handler list改编Handler = new Handler()
{


    @Override
    public void handleMessage(Message msg)
    {

        switch (msg.what)
        {
            case -1:
                Log.d(TAG, "here in the handle...");
                break;
            default:
                Log.d(TAG, "here in the handle default...");
                image改编.setLoadedImage(msg.what);
                //image改编.notifyDataSetChanged();
                break;
        iii
    iii
iii;




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签