0

I've been using Parse.com for my photo sharing app on android but I'm having a few problems displaying images and data in a listview.

Basically I want to fetch the data from Parse.com and display it in a listView.

In my MainActivity I have the method downloadContentForMainView() - where I fetch my data and insert it in a HashMap - and after all my data is fetched I use an Adapter to show the data in a listView.

Here's my code:

private void downloadContentForMainView() throws ParseException
{
    ParseQuery query = new ParseQuery("PhotoUpload");
    query.whereEqualTo("User", username);
    query.findInBackground(new FindCallback() {
        public void done(List<ParseObject> content, ParseException pEx) {
            // TODO Auto-generated method stub
            if(pEx == null && content!=null)
            {
                if(!(content.isEmpty()))
                {
                        if((content!=null) && (!(content.isEmpty())))
                        {
                            for(ParseObject aParseObject : content)
                            {
                                ParseFile image = (ParseFile) aParseObject.get("photp");
                                image.getDataInBackground(new GetDataCallback() {

                                    @Override
                                    public void done(byte[] imageInBytes, ParseException pEx) {
                                        // TODO Auto-generated method stub
                                        bmp = BitmapFactory.decodeByteArray(imageInBytes, 0, imageInBytes.length);
                                    }
                                });

                                String objectId = aParseObject.getObjectId();
                                String date = aParseObject.getCreatedAt().toGMTString();
                                infoHashMap.put("objectId", objectId);
                                infoHashMap.put("Date", date);
                                infoHashMap.put("photo", bmp);

                            }
                        }
                        else
                        {
                            Toast toast2 = Toast.makeText(context,"Couldn't fetch data from server", Toast.LENGTH_LONG);
                            toast2.show();
                        }
                }
            }
        }
    });

    contentForList.add(infoHashMap);
    lazyAdapter = new LazyAdapter(this,contentForList);
    listView.setAdapter(lazyAdapter);

}

After I've fetched all my data from server - I use an Adapter to show data in a listView - but my activity remains black.

Does anyone have any ideea why?

Later Update:

Here's my LazyAdapter

public class LazyAdapter extends BaseAdapter{

private Activity activity;
private ArrayList<HashMap<String, Object>> contentList;
private static LayoutInflater inflater = null;  

public LazyAdapter(Activity a, ArrayList<HashMap<String, Object>> contentForList)
{
    this.activity=a;
    this.contentList=contentForList;
    inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return contentList.size();
}

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

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

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    ImageView logo = (ImageView)vi.findViewById(R.id.logo); // title
    TextView date = (TextView)vi.findViewById(R.id.label); // artist name

    HashMap<String, Object> info = new HashMap<String,Object>();
    info = contentList.get(position);
    String in =(String)info.get("Date");
    // Setting all values in listview
    date.setText(in);
    Bitmap bmp = (Bitmap) info.get("photo");
    logo.setImageBitmap(bmp);
    return vi;
}

}

2
  • 1
    Show us your lazy adapter class Commented Nov 26, 2012 at 1:29
  • First, shouldn't the line contentForList.add(infoHashMap); be in that for loop so you add all the Maps instead of adding a single Map with the last values? Second, did you check to see if you have some values in the contentForList list that you pass to the adapter? Third, is the ListView the only widget in the layout of the Activity(if not do you mind adding that layout file)? Commented Nov 26, 2012 at 15:23

2 Answers 2

5

sorry for coming in late but I feel this might be useful -
http://www.androidbegin.com/tutorial/android-parse-com-listview-images-and-texts-tutorial/

Sign up to request clarification or add additional context in comments.

Comments

0

I think your adapter goes wrong

public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null)
    vi = inflater.inflate(R.layout.list_row, null);

ImageView logo = (ImageView)vi.findViewById(R.id.logo); // title
TextView date = (TextView)vi.findViewById(R.id.label); // artist name

HashMap<String, Object> info = new HashMap<String,Object>();
info = contentList.get(position);
String in =(String)info.get("Date");
// Setting all values in listview
date.setText(in);
Bitmap bmp = (Bitmap) info.get("photo");
logo.setImageBitmap(bmp);
return vi;

}

You are checking whether view is null or not..Please double check that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.