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;
}
}
enter code here
contentForList.add(infoHashMap);
be in thatfor
loop so you add all theMaps
instead of adding a singleMap
with the last values? Second, did you check to see if you have some values in thecontentForList
list that you pass to the adapter? Third, is theListView
the only widget in the layout of theActivity
(if not do you mind adding that layout file)? – Luksprog Nov 26 '12 at 15:23