开发者

Android: setting visibility of an image in the listview issue

开发者 https://www.devze.com 2023-03-31 18:49 出处:网络
I\'m having a listview and showing cam image with number of imagege count. My code goes as below TextView imageCountview = (TextView) row.findViewById(R.id.TextViewImageCount); ;

I'm having a listview and showing cam image with number of imagege count. My code goes as below

           TextView imageCountview = (TextView) row.findViewById(R.id.TextViewImageCount); ;
            //checking whether count is zero, if so hiding both image and count
            if(ImageCount.equals("0")){
                imageCountview.setVisibility(8);
                ImageView camimage = (ImageView) row.findViewById(R.id.imageViewlistcam);
    开发者_如何学编程            camimage.setVisibility(8);
            }
            else{
                imageCountview.setText(ImageCount);
            }

Now My problem is, when the list is loaded everyhing is fine and image is shown when the count is greater than zero. Now I kept on adding more elements to the listview till it makes the scroll bar. problem begins now

when I scroll up, part of the list elements goes behind the screen which is expected behaviour. when I scroll down the cam images are vanished even though it was shown previously. Its very peculior behaviour in the list. what am I missign here?? can someone help me out.

Thanks for your time in advance.

my adapter

class MyIncidentAdapter extends ArrayAdapter{

        public MyIncidentAdapter(Context context, int textViewResourceId,
                ArrayList<String> dbResults) {
            super(context, textViewResourceId, dbResults);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            if (row == null) {
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.row_incident, parent, false);
            }

            TextView incidentID = (TextView) row.findViewById(R.id.label_incident);
            incidentID.setText((db_results.get(position)).toString());

            String Final = null;
            String ImageCount = "0";
            String VideoCount = "0";
            String RecordingCount="0";
            //getting image count
            SQLiteDatabase db10;
            db10 = openOrCreateDatabase("filestore", MODE_PRIVATE, null);
            Cursor cursor = db10.rawQuery(
                    "SELECT count(urls) as numbers FROM files where incident_id='"+((db_results.get(position)).toString())+"'", null);
            while (cursor.moveToNext()) {
                ImageCount = String.valueOf(cursor.getString(cursor
                        .getColumnIndex("numbers")));
            }
            cursor.close();

            //getting video
            Cursor cursor1 = db10.rawQuery(
                    "SELECT count(urls) as numbers FROM videos where incident_id='"+((db_results.get(position)).toString())+"'", null);
            while (cursor1.moveToNext()) {
                VideoCount = String.valueOf(cursor1.getString(cursor1
                        .getColumnIndex("numbers")));
            }
            cursor1.close();

            //getting audio count
            Cursor cursor11 = db10.rawQuery(
                    "SELECT count(urls) as numbers FROM audios where incident_id='"+((db_results.get(position)).toString())+"'", null);
            while (cursor11.moveToNext()) {
                RecordingCount = String.valueOf(cursor11.getString(cursor11
                        .getColumnIndex("numbers")));
            }
            cursor11.close();



            //Final = "Image:"+ImageCount+ "      Video:"+VideoCount+ "      Audio:"+RecordingCount;
            //TextView countinfo = (TextView) row.findViewById(R.id.textViewCount);
            //countinfo.setText(Final);

            TextView imageCountview = (TextView) row.findViewById(R.id.TextViewImageCount); ;
            //checking whether count is zero, if so hiding both image and count
            if(ImageCount.equals("0")){
                imageCountview.setVisibility(8);
                ImageView camimage = (ImageView) row.findViewById(R.id.imageViewlistcam);
                camimage.setVisibility(8);
            }
            else{
                imageCountview.setText(ImageCount);
            }


            TextView videoCountview = (TextView) row.findViewById(R.id.textViewVideoCount);
            if(VideoCount.equals("0")){
                videoCountview.setVisibility(8);
                ImageView imgvid = (ImageView)row.findViewById(R.id.imageViewlistvid);
                imgvid.setVisibility(8);
            }
            else{
                videoCountview.setText(VideoCount);
            }


            TextView audioCountview = (TextView) row.findViewById(R.id.textViewAudioCount);
            if(RecordingCount.equals("0")){
                audioCountview.setVisibility(8);
                ImageView audioimg = (ImageView)row.findViewById(R.id.imageViewlistaud);
                audioimg.setVisibility(8);
            }
            else{
                audioCountview.setText(RecordingCount);
            }

            String InsDate=null;
            Cursor cursor111 = db10.rawQuery(
                    "SELECT incident_date FROM incident where incident_id='"+((db_results.get(position)).toString())+"'", null);
            while (cursor111.moveToNext()) {
                InsDate = String.valueOf(cursor111.getString(cursor111
                        .getColumnIndex("incident_date")));
            }
            cursor111.close();

            TextView incidentDate = (TextView) row.findViewById(R.id.label_date);
            incidentDate.setText(InsDate);

            Cursor cursor1111 = db10.rawQuery(
                    "SELECT description FROM incident where incident_id='"+((db_results.get(position)).toString())+"'", null);
            while (cursor1111.moveToNext()) {
                description = String.valueOf(cursor1111.getString(cursor1111
                        .getColumnIndex("description")));
            }
            cursor1111.close();
            db10.close();
            TextView incidentDesc = (TextView) row.findViewById(R.id.label_des);


            if(description.equals(" ")){
                incidentDesc.setVisibility(8);
            }
            else{
                incidentDesc.setText(description.trim());
            }



            return row;
        }


Pass null in the parent paramter to inflate api.

row = inflater.inflate(R.layout.row_incident, null, false);


the answer found with this quesiton. simple I have to show again wot ever I hide using setvisibility method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号