Skip to content

Instantly share code, notes, and snippets.

@rileyrg
Created August 18, 2014 15:28
Show Gist options
  • Save rileyrg/342a02d5b569bc8a6f5c to your computer and use it in GitHub Desktop.
Save rileyrg/342a02d5b569bc8a6f5c to your computer and use it in GitHub Desktop.
First view adaptor
public class DisplayDebug {
private LinkedHashMap<String, String> debugMap = new LinkedHashMap();
public void put(String var, String val) {
debugMap.put(var, val);
}
public DisplayDebug(Activity activity) {
ListView listview = (ListView) activity.findViewById(R.id.debugview);
DebugAdaptor adapter = new DebugAdaptor(activity, debugMap);
listview.setAdapter(adapter);
}
}
public class DebugAdaptor extends BaseAdapter {
LinkedHashMap<String,String> debugMap;
Context c;
public DebugAdaptor(Context c, LinkedHashMap<String, String> debugMap) {
this.c=c;
this.debugMap = debugMap;
}
@Override
public int getCount() {
return debugMap.size();
}
@Override
public Object getItem(int position) {
Iterator iterator = debugMap.entrySet().iterator();
int n = 0;
while(iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
if(n == position){
return entry;
}
n ++;
}
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// this is found "X","1" for example
Map.Entry m = (Map.Entry) getItem(position);
LayoutInflater inflater = (LayoutInflater) c.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
//worry about convertView later
//** crash here
View v = inflater.inflate(R.layout.debug_list_item, parent);
return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment