android - Compilation error creating an adapter in a fragment -
i have fragment contains several views including listview. in order set adpater listview, thought i'd recycle old (working) code i'd written in activity. code in activity looked this:
adapter = new myadapter( this, list_of_things, r.layout.custom_row_view, new string[] {"label","day","time"}, new int[] {r.id.text1,r.id.text3, r.id.text2} );
where myadapter method within activity's class, defined so...
public class myadapter extends simpleadapter {
now tried put same myadapter method inside fragment class , called
adapter = new myadapter( this, list_of_things, r.layout.custom_row_view, new string[] {"label","day","time"}, new int[] {r.id.text1,r.id.text3, r.id.text2} );
but compile time error:
the constructor mytestfragment.myadapter(mytestfragment, arraylist<hashmap<string,string>>, int, string[], int[]) undefined
i don't know whether bug minor typo - or whether more fundamental, not being allowed adapters within fragments.
use getactivity()
instead of in myadapter
adapter = new myadapter( getactivity(), list_of_things, r.layout.custom_row_view, new string[] {"label","day","time"}, new int[] {r.id.text1,r.id.text3, r.id.text2} );
because this
in myadapter referencing fragment
, not activity
.
Comments
Post a Comment