Custom ArrayAdapter showing a blank screen in my Fragment



So I've just been messing around with android for a little bit and I've run into a bit of a snag. The fragment where I am instantiating ListOfJokesTypesAdapter for some reason is not displaying a listview populated with the Data from my JokeData class.


All that I get is a blank screen (no errors or anything of that nature).


This is just a proof of concept thing I've been working on so any help would be greatly appreciated. Why is it that this particular custom adapter is not working while my MainClassAdapter is working just fine.


The Code


My Joke Class:



public class Joke {

private String jokeSetup;
private String jokePunchline;

public Joke(String jokeSetup, String jokePunchline) {
this.jokeSetup = jokeSetup;
this.jokePunchline = jokePunchline;
}

public String getJokeSetup() {
return jokeSetup;
}

public void setJokeSetup(String jokeSetup) {
this.jokeSetup = jokeSetup;
}

public String getJokePunchline() {
return jokePunchline;
}

public void setJokePunchline(String jokePunchline) {
this.jokePunchline = jokePunchline;
}
}


My JokeListClass



public class JokeListData {

private String listName;
private List<Joke> arrayListOfJokes;

public JokeListData(String listName, List<Joke> arrayListOfJokes) {
this.listName = listName;
this.arrayListOfJokes = arrayListOfJokes;
}

public String getListName() {
return listName;
}

public void setListName(String listName) {
this.listName = listName;
}

public List<Joke> getArrayListOfJokes() {
return arrayListOfJokes;
}

public void setArrayListOfJokes(ArrayList<Joke> arrayListOfJokes) {
this.arrayListOfJokes = arrayListOfJokes;
}
}


My Actual Joke Data



public class JokeData {



private static List<Joke> dogJokes = new ArrayList<Joke>(){

{
add(new Joke("Dogs", "Bark"));
add(new Joke("Dogs", "Woof"));
add(new Joke("Dogs", "Howl"));
add(new Joke("Dogs", "Sniff"));
}
};


private static List<Joke> catJokes = new ArrayList<Joke> (){
{
add(new Joke("Cats", "woof"));
add(new Joke("Dogs", "Meow"));
}
};

static List<JokeListData> dataOfJokeList = new ArrayList<JokeListData>();

public static void addEntries(){
dataOfJokeList.add(new JokeListData("Cat Jokes", catJokes));
dataOfJokeList.add(new JokeListData("Dog Jokes", dogJokes));
}

}


The Adapter



public class ListOfJokeTypesAdapter extends ArrayAdapter<JokeListData> {

Context mContext;
int mLayoutId;
List<JokeListData> mList;

public ListOfJokeTypesAdapter(Context context, int resource, List<JokeListData> objects) {
super(context, resource, objects);
this.mContext = context;
this.mLayoutId = resource;
this.mList = objects;
}


@Override
public int getCount() {
return super.getCount();
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;

if(convertView == null){
LayoutInflater inflater = LayoutInflater.from(mContext);
convertView = inflater.inflate(mLayoutId,parent,false);

holder = new ViewHolder();

holder.mTextView = (TextView) convertView.findViewById(R.id.rowForMainList);

convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}

JokeListData jokeListData = mList.get(position);

holder.mTextView.setText(jokeListData.getListName());

return convertView;
}

private static class ViewHolder{
TextView mTextView;
}
}


The Fragment which utilizes the adapter



public class ListOfJokeTypesFragment extends Fragment {

ListView mListView;
ListOfJokeTypesAdapter listOfJokeTypesAdapter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.joke_type_fragment,container,false);
JokeData.addEntries();
mListView = (ListView)view.findViewById(R.id.jokeTypeListView);
listOfJokeTypesAdapter = new ListOfJokeTypesAdapter(getActivity().getApplicationContext(),R.layout.row,JokeData.dataOfJokeList);
mListView.setAdapter(listOfJokeTypesAdapter);

return view;
}
}


The relevant XML:


joke_type_fragment.xml



<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@+id/jokeTypeListView"
android:layout_width="match_parent"
android:layout_height="match_parent">

</ListView>

</LinearLayout>


row.xml



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:layout_margin="5dp"
android:gravity="center_vertical"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#eeeeee"
android:textStyle="bold"
android:layout_margin="5dp"
android:padding="5dp"
android:background="#2299dd"
android:textSize="20sp"
android:text="Main Activity Items"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rowForMainList"/>
</LinearLayout>

</LinearLayout>

Tiada ulasan:

Catat Ulasan