Here s my getView() method. I am getting null pointer exception while inflating. There are so many answers for the same questions. This is used inside a fragment. But that doesn’t suit me.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Context con = null;
View vi=convertView;
if(convertView==null){
LayoutInflater inflater = (LayoutInflater)con.getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vi = inflater.inflate(R.layout.stores_listview_layout, null);
}
TextView tv = (TextView)vi.findViewById(R.id.store_name);
tv.setText(storeData.get(position).get("merchantName"));
return vi;
}
What is the mistake I am doing here?
Update: This works!
View vi=convertView;
Context c = null;
if(convertView==null){
LayoutInflater inflater = getLayoutInflater(null);
vi = inflater.inflate(R.layout.stores_listview_layout, parent, false);
}
1 Answer