I am using Sectioned List in my activity which extends ListActivity
but now as i need to add Actionbar to this activity so i cant use ListActivity here.
So i am trying to use ListView for the same.
But i am not getting how to set adapter to the Listview.
Because i need to set custom adapter used for SectionedListView.
But when i used it for simple ListView it gives NullPointer Exception.
i had wasted more than enough time for it
please help me.
this is the xml file of ListView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
and this is the adapter used for (ListActivity).
public class EntryAdapter extends ArrayAdapter<Item> {
private Context context;
private ArrayList<Item> items;
private LayoutInflater vi;
private ImageDownloader mImageDownloader;
public EntryAdapter(Context context,ArrayList<Item> items, ImageDownloader mImageDownloader) {
super(context,0, items);
this.context = context;
this.items = items;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mImageDownloader = mImageDownloader;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
Log.v("position in entry adapter", ""+position);
final Item i = items.get(position);
if (i != null) {
if(i.isSection()){
SectionItem si = (SectionItem)i;
v = vi.inflate(R.layout.list_item_section, null);
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
final TextView sectionView = (TextView) v.findViewById(R.id.list_item_section_text);
sectionView.setText(si.getTitle());
}else{
EntryItem ei = (EntryItem)i;
v = vi.inflate(R.layout.list_item_entry, null);
final TextView title = (TextView)v.findViewById(R.id.list_item_entry_title);
final TextView subtitle = (TextView)v.findViewById(R.id.list_item_entry_summary);
final ImageView cat_icon = (ImageView)v.findViewById(R.id.category_icon);
final ImageView channel_icon = (ImageView)v.findViewById(R.id.channel_icon);
if (title != null)
title.setText(ei.title);
if(subtitle != null)
subtitle.setText(ei.subtitle);
if(cat_icon != null)
{
if(ei.catIcon != null)
cat_icon.setImageBitmap(ei.catIcon);
else
cat_icon.setVisibility(View.INVISIBLE);
}
if(channel_icon !=null)
{
if(ei.url != null)
{
mImageDownloader.download(ei.url,channel_icon);
Log.v("url in adapter", ei.url);
}
else
channel_icon.setVisibility(View.INVISIBLE);
}
}
}
return v;
}
}
mList = (ListView) findViewById(R.id.list);
EntryAdapter adapter = new EntryAdapter(this, items, mImageDownloader);
mList.setAdapter(adapter);
mList.setOnItemClickListener(this);
Thanks
Mahaveer.
What you need to do for changing a class that extends
ListActivitytoActivity,