Hey there.
I'm loading in data dynamically like so..
ParseQuery<Assignment> query = ParseQuery.getQuery(Assignment.class);
query.whereEqualTo("owner", ParseUser.getCurrentUser());
query.fromLocalDatastore();
query.findInBackground(new FindCallback<Assignment>() {
@Override
public void done(List<Assignment> results, ParseException e) {
finishedList = new ArrayList<Assignment>();
unfinishedList = new ArrayList<Assignment>();
completed=0;
uncomplete=0;
for(Assignment a: results){
Log.d("Assignment", a.getName());
if(a.getComplete()){
finishedList.add(a);
completed++;
}
else{
unfinishedList.add(a);
uncomplete++;
}
}
notifyDataSetChanged();
//if(mListener!=null)setListAdapter(new ArrayAdapter<Assignment>(getActivity(),
// android.R.layout.simple_list_item_1, android.R.id.text1, results));
}
});
I have attached the entire file other then the actual row rendering. If i remove notifydatasetchanged it will work but will not show the rows which defeats the point.
package com.michaellatman.studybranch.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.applidium.headerlistview.SectionAdapter;
import com.michaellatman.studybranch.R;
import com.michaellatman.studybranch.objects.Assignment;
import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* Created by michael on 8/10/14.
*/
public class AssignmentAdapter extends SectionAdapter {
int completed = 0;
int uncomplete = 0;
List<Assignment> finishedList = null;
List<Assignment> unfinishedList = null;
Context ctx = null;
public AssignmentAdapter(Context ctx){
this.ctx = ctx;
ParseQuery<Assignment> query = ParseQuery.getQuery(Assignment.class);
query.whereEqualTo("owner", ParseUser.getCurrentUser());
query.fromLocalDatastore();
query.findInBackground(new FindCallback<Assignment>() {
@Override
public void done(List<Assignment> results, ParseException e) {
finishedList = new ArrayList<Assignment>();
unfinishedList = new ArrayList<Assignment>();
completed=0;
uncomplete=0;
for(Assignment a: results){
Log.d("Assignment", a.getName());
if(a.getComplete()){
finishedList.add(a);
completed++;
}
else{
unfinishedList.add(a);
uncomplete++;
}
}
notifyDataSetChanged();
//if(mListener!=null)setListAdapter(new ArrayAdapter<Assignment>(getActivity(),
// android.R.layout.simple_list_item_1, android.R.id.text1, results));
}
});
}
@Override
public boolean hasSectionHeaderView(int section) {
return true;
}
@Override
public int getSectionHeaderViewTypeCount() {
return 1;
}
@Override
public int getSectionHeaderItemViewType(int section) {
return 1;
}
@Override
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = vi.inflate(R.layout.item_header, null);
}
//((TextView) convertView).setText("Header for section " + section);
return convertView;
}
@Override
public int numberOfSections() {
return 2;
}
@Override
public int numberOfRows(int section) {
Log.d("NumRows",""+section+" "+uncomplete+" "+completed);
switch (section){
case 0:
return uncomplete;
case 1:
return completed;
}
return section;
}
@Override
public View getRowView(int section, int row, View convertView, ViewGroup parent) {
View v = convertView;
if (convertView == null) {
LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.item_assignment, null);
}
......
return v;
}
@Override
public Object getRowItem(int section, int row) {
Log.d("Get","row");
switch (section){
case 0:
return unfinishedList.get(row);
case 1:
return finishedList.get(row);
}
return null;
}
}