简体   繁体   中英

update a single row in a ListView?

My android app have custom list view like

在此处输入图片说明

the numbers are total number of days one student was ,present,absent or late.Now i want if i press any redio button (suppose present button then total number of present will 101,if i press late then total present will be 100 and total number of late will be 101) i mean i will change text in runtime.How can i do this.I have found this

Redraw a single row in a listview

and

How can I update a single row in a ListView?

In the first,the target vew have to get from user,how can i do that,i am not understanding the second one either

For updating a single list item you have to get the view at the specified position, and then update the view.

You can get list_item using the following method,

public View getViewByPosition(int position) {
        final int firstListItemPosition = filesListview.getFirstVisiblePosition();
        final int lastListItemPosition = firstListItemPosition + filesListview.getChildCount() - 1;
        if (position < firstListItemPosition || position > lastListItemPosition) {
            // return filesListview.getAdapter().getView(position, filesListview.getChildAt(position), filesListview);
            return null;
        } else {
            final int childIndex = position - firstListItemPosition;
            return filesListview.getChildAt(childIndex);
        }
    }

The above the method will return the view if the View at the given position is visible in the listview otherwise it will return null. For example if the list view contains 20 elements and currently listview is showing 0-6 elements then above method will return the views for 0-6 and others will return null.

       View viewByPosition = getViewByPosition(position;
        // If the retrived view is not null then udpate the view otherwise ignore.
        if (viewByPosition != null) {
           //Update the view
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM