Skip List Box

I assume getView() is called for each item in the list, but my question is: can we show the row if the data associated with this row is zero. I want to do this only inside getView () .

Example:

If the alerts for the person whose name is to be displayed in the list view are null. I do not want to display this person’s name in a list.

+6
source share
2 answers

You can set the visibility of this line to “leave” the last line before returning the view - this should work for you.

Edit: Make sure that visibility is visible if the content is not null - otherwise all views will become “lost” because the ListView reuses the views.

 myView.setVisibility((myData == null) ? View.GONE : View.VISIBLE); 
+20
source

Hi Pals, I tried to set the visibility to invisible, but still I can see an empty line in the list, so I change a bit and worked according to my need, so it’s worth sharing if someone needs a similar result like mine.

I use List as a source. My requirement was to skip a few applications, so I did it, I removed this application from the list and the modified dataset

 public AppListAdapter(Context context, List<ApplicationInfo> appList) { this.context = context; this.appList = appList; inflater = LayoutInflater.from(context); localStorage = new LocalStorage(context); pm = context.getPackageManager(); } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) convertView = inflater.inflate(R.layout.applist_item, parent, false); // Other lines of code if(appName.length()==0 || getItem(position).packageName.equals("package.name.to.skip")) { appList.remove(position); notifyDataSetChanged(); } return convertView; } 

Lines of concern

appList.remove (position);
notifyDataSetChanged ();

Your suggestions and corrections are always welcome. AzmatHunzai

+1
source

Source: https://habr.com/ru/post/918279/


All Articles