timbats1993
timbats1993

Reputation: 101

Android - Making a listview row invisible

I am attempting to make a list view row empty if it has no text. I have achieved this before, but I'm not sure how I did it. At the moment, I have managed to get it to not show anything when the text is equal to nothing, however it still shows the row border.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, MainActivity.values) {
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                View view = super.getView(position, convertView, parent);
                TextView text1 = (TextView) view.findViewById(android.R.id.text1);
                TextView text2 = (TextView) view.findViewById(android.R.id.text2);


                text1.setText(MainActivity.values[position]);
                text2.setText(MainActivity.numvalues[position]);

                    if (MainActivity.values[position].equals("")) {
                        text1.setVisibility(View.INVISIBLE);
                        text1.setVisibility(View.GONE);
                        text2.setVisibility(View.INVISIBLE);
                        text2.setVisibility(View.GONE);
                        //convertView.setVisibility(View.INVISIBLE);
                        //convertView.setVisibility(View.GONE);
                        view.setVisibility(View.INVISIBLE);
                        view.setVisibility(View.GONE);
                    }
                    else {
                        text1.setVisibility(View.VISIBLE);
                        text2.setVisibility(View.VISIBLE);
                        //convertView.setVisibility(View.INVISIBLE);
                        //convertView.setVisibility(View.GONE);
                        view.setVisibility(View.VISIBLE);
                    }

                return view;
              }
            };

Upvotes: 0

Views: 151

Answers (2)

Nik Myers
Nik Myers

Reputation: 1873

VIEW.GONE won't work as you want, i've tried it, but there is one thing you can do to avoid this problem at all, maybe you should remove all of your empty rows before you past your items into adapter?

Upvotes: 1

Vladimir Samoylov
Vladimir Samoylov

Reputation: 521

Before init ArrayAdapter remove from MainActivity.values and MainActivity.numvalues items that don't need to show.

Upvotes: 1

Related Questions