I'm little lost filling a ListView from a List. I can fill it with one element, but I want to get three elements from the object, so when I touch each element the app go to the link it contain. In my actual code I just can show the title
protected void onPostExecute (Boolean result){
List <String> title = new ArrayList<String>();
List <String> link = new ArrayList<>();
List <String> date = new ArrayList<>();
for(int i=0;i<news.size();i++)
{
title.add(news.get(i).getTitle());
link.add(news.get(i).getLink());
date.add(news.get(i).getDate());
}
ArrayAdapter <String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,title);
result.setAdapter(adapter);
dialog.dismiss();
}
In the arraylist date
and link
, I save the correct data, but I just can use one of them. My intention is to put date below the title and when you touch each element, the browser opens with the link selected.
Thanks a lot.
EDIT: I've done the custom adapter, but it gives me an error.
class CustomAdapter extends ArrayAdapter<whatsnew> {
public CustomAdapter(Context context, whatsnew[] data) {
super(context, R.layout.listitem, data);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(getContext());
View item = inflater.inflate(R.layout.listitem, null); //This give me a warning
TextView lblTitle = (TextView)item.findViewById(R.id.lbltitle);
lblTitle.setText(data[position].getTitle());
TextView lbldate = (TextView)item.findViewById(R.id.lbldate);
lbldate.setText(data[position].getFecha());
return(item);
}
}
CustomAdapter adaptader = new CuestomAdapter(getActivity(), data);
result.setAdapter(adaptador);
dialog.dismiss();
My Logcat says:
Java NullPointerException: storage == null
The solution is change "whatsnew[] data" by "List data" in the public CustomAdapter method since I have all the data in ArrayList named data.