I have a problem that I've tried to resolve for some time with the tips I've found from googling on this issue.
My SimpleAdapter looks like this:
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, contactList,
R.layout.list_item, new String[]{"namn", "avdelning", "epost", "mobil", "telnr"},
new int[]{R.id.email, R.id.mobile, R.id.epost, R.id.mobil, R.id.telnr});
lv.setAdapter(adapter);
It displays items in a listview that is gathered from pushing the search query button in my searchview which fetches data from a JSON api.
My issue is that some of the items are empty which results in an empty space. I want this empty space to disappear.
I've tried with the code below but never figured out how to get it to work
ListAdapter adapter2 = new SimpleAdapter(this, contactList, R.layout.list_item, new String[]{"mobil"
}, new int[]{R.id.mobil})
{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
holder = new ViewHolder();
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
holder.textView = (TextView) v.findViewById(R.id.mobil);
//other stuff
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
}
HashMap<String, String> contact = contactList.get(position);
if (TextUtils.isEmpty(contact.get("mobil"))) {
holder.textView.setVisibility(View.GONE);
holder.textView.setVisibility(View.INVISIBLE);
notifyDataSetChanged();
} else {
holder.textView.setVisibility(View.VISIBLE);
}
//do the same thing for other possible views.
return v;
}
class ViewHolder {
TextView textView;
//your other views
}
};
any tips?
notifyDataSetChanged
with updated list.