I have just built a new class that extends BaseAdapter. I believe that I have set up everything correctly however, when i attempt to set my adapter inside the fragment I would like to use it in I am getting the following error:
The constructor HomeBase(Home) is undefined
HomeBase is the name of the class that I built.
here is the constructor for the BaseAdapter(I would add the whole class but it is rather long):
// constructor call
HomeBase(Context c){
context=c;
list = new ArrayList<SingleRow>();
Resources res = c.getResources();
String [] title; // temporary storage array for titles
title = res.getStringArray(R.id.title); // gets string array title and temporarily stores it in title[]
String [] invites; // temporary storage array for titles
invites = res.getStringArray(R.id.description); // gets string array invites and temporarily stores it in invites[]
int[] images = {R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img8,
R.drawable.img9, R.drawable.img10, R.drawable.img11}; // get images and store them into an array
// Loop to insert data from the different arrays into their respective single row objects, and those objects into the ArrayList list
for(int i=0; i<10; i++)
{
list.add(new SingleRow (title[i], invites[i], images[i] ));
}
}
this is the object that is used to populate the ArrayList list
public class SingleRow {
String title;
String description;
int image;
SingleRow(String title, String description, int image){
this.title=title;
this.description=description;
this.image=image;
}
}
aaand here is the onCreate() method from the fragment that is going to use the BaseAdapter:
@Override
public void onCreate(Bundle SavedInstanceState){
super.onCreate(SavedInstanceState);
list=(ListView)getView().findViewById(R.id.list_view);
list.setAdapter(new HomeBase(this));
Log.v(HOME, "onCreate() was called");
}
I'm learning about all things Android now, and would appreciate any helpful suggestions.
Thanks,
James
If your piece where you are putting your adapter inherit from ListFragment
@Override public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Initially there is no data
setEmptyText("No Data Here");
// Create an empty adapter we will use to display the loaded data.
mAdapter = new CustomArrayAdapter(getActivity());
setListAdapter(mAdapter);
}
Or if in a Fragment
, move your code as below:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list_view, container, false);
list=(ListView)view.findViewById(R.id.list_view);
list.setAdapter(new HomeBase(getActivity()));
Log.v(HOME, "onCreate() was called");
return view;
}