Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有Facebook ProfilePictureView小部件的ListView导致延迟_Android_Facebook_Android Listview - Fatal编程技术网

Android 带有Facebook ProfilePictureView小部件的ListView导致延迟

Android 带有Facebook ProfilePictureView小部件的ListView导致延迟,android,facebook,android-listview,Android,Facebook,Android Listview,我已经为包含facebook SDK 3.5中ProfilePictureView元素的listview做了自定义适配器。这里的问题是:由于加载配置文件图像,如果我删除它,滚动时会有很大的延迟。尽管异步加载,但延迟要小得多 我怎样才能解决这个问题?下面是我的自定义适配器 public class UserAdapter extends ArrayAdapter<User> { /** Contacts list */ private List<User> Users;

我已经为包含facebook SDK 3.5中ProfilePictureView元素的listview做了自定义适配器。这里的问题是:由于加载配置文件图像,如果我删除它,滚动时会有很大的延迟。尽管异步加载,但延迟要小得多

我怎样才能解决这个问题?下面是我的自定义适配器

public class UserAdapter extends ArrayAdapter<User> {

/** Contacts list */
private List<User> Users;

/** Context */
private Activity Ctx;

public UserAdapter(Context context, int textViewResourceId, List<User> users) {
    super(context, textViewResourceId, users);
    this.Ctx = (Activity) context;
    this.Users = users;
}

@Override
public View getView(int position, View v, ViewGroup parent) {
    // Keeps reference to avoid future findViewById()
    UsersViewHolder viewHolder;

    if (v == null) {
        LayoutInflater li = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = li.inflate(R.layout.row_friend, parent, false);

        viewHolder = new UsersViewHolder();
        viewHolder.mUserName = (CustomTextView) v.findViewById(R.id.friendName);
        viewHolder.mUserDescription = (CustomTextView) v.findViewById(R.id.friendDescription);
        viewHolder.mProfilePicture = (ProfilePictureView) v.findViewById(R.id.userPicture); 
        v.setTag(viewHolder);
    } else {
        viewHolder = (UsersViewHolder) v.getTag();
    }  

    User mUser = Users.get(position);
    if (mUser != null) {
        viewHolder.mUserName.setText(""+mUser.getName()+" "+mUser.getLastName());
        viewHolder.mUserDescription.setText(mUser.getEmail());
        viewHolder.mProfilePicture.setProfileId(mUser.getIdFB()); //problem
        viewHolder.mProfilePicture.setCropped(true);              //problem
    }
    return v;
}

static class UsersViewHolder {
    LinearLayout mLayout;
    ProfilePictureView mProfilePicture;
    CustomTextView mUserName;
    CustomTextView mUserDescription;
}
}

我也遇到了同样的问题,所以我决定使用ImageView并直接从facebook api下载图像。以下是执行此操作的代码:

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.ImageView;

public class DownloadImage extends AsyncTask<String, Void, Bitmap> {

private ImageView layoutimage;
private Bitmap bitmap;
private boolean malformedUrl;

public DownloadImage(ImageView Image) {
    this.layoutimage = Image;
}

public Bitmap getBitmap() {
    return bitmap;
}

@Override
protected void onPreExecute() {
}

@Override
protected Bitmap doInBackground(String... Image_URL) {

    String url = Image_URL[0];
    try {

        // Handle redirect
        URL obj = new URL(url);
        HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
        int status = conn.getResponseCode();
        if (status != HttpURLConnection.HTTP_OK) {
            if (status == HttpURLConnection.HTTP_MOVED_TEMP
                    || status == HttpURLConnection.HTTP_MOVED_PERM
                    || status == HttpURLConnection.HTTP_SEE_OTHER)
                url = conn.getHeaderField("Location");
        }

        // Get bitmap from URL
        Bitmap bitmap = null;
        try {
            // Download Image from URL
            InputStream input = new java.net.URL(url)
                    .openStream();
            bitmap = BitmapFactory.decodeStream(input);
        } catch (Exception e) {
            // Error Log
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return bitmap;
    } catch (MalformedURLException e) {
        malformedUrl = true;
        return null;
    } catch (IOException e) {
        malformedUrl = true;
        return null;
    }
}

@Override
protected void onPostExecute(Bitmap result) {
    // Set image into image.xml layout
    if (layoutimage != null)
        layoutimage.setImageBitmap(result);
    bitmap = result;
}
}
DownloadImage di = new DownloadImage(category.findViewById(R.id.your_image_view));
di.execute("http://graph.facebook.com/" + FACEBOOK_ID + "/picture?type=small);