-1

My android app have custom list view like

enter image description here

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

Community
  • 1
  • 1

1 Answers1

-1

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
        }
Kartheek
  • 7,020
  • 3
  • 28
  • 43
  • @Selvin Till now i didn't read anything like that, do you have any reference How can you say that ?, and i had already worked on that it is working perfectly without any errors and warnings. – Kartheek Jun 25 '15 at 09:10
  • @Selvin Ok my question is how can you say that ? Do you have any reference for that I have searched but i didn't found such things. While searching i found a similar question http://stackoverflow.com/questions/3724874/how-can-i-update-a-single-row-in-a-listview and look at the answer of mreichelt – Kartheek Jun 25 '15 at 09:25
  • tnx for answer.But can you tell me how i get the position(i am new to android,so it is hard for me understand little things) – Amir Hossain Jun 25 '15 at 09:29
  • @AmirHossain that position refers to position of the list item which you want to update. If want to update the 2nd list item then pass the position as 2 – Kartheek Jun 25 '15 at 09:31
  • @ Kartheek but i want when user check the radio button,then the listview text update,How can i do this? – Amir Hossain Jun 25 '15 at 09:37
  • @AmirHossain I guess you have added the listener for the radio button, post the getView() method of your adapter. so that i help you better. – Kartheek Jun 25 '15 at 09:39
  • @Selvin Arguing without any reference is a waste of time.If have any reference let me know otherwise keep calm. Once go through the link http://shelves.googlecode.com/svn/trunk/Shelves/src/org/curiouscreature/android/shelves/activity/ShelvesActivity.java and look at updateBookCovers() method it is developed by Romanian Guy a developer at Google. – Kartheek Jun 25 '15 at 09:45
  • @AmirHossain I guess you are updating the text in the updateView(). to prevent the text from updating, remove the listener for the radiobutton by setting it null, update the radio button then add back the listener to radio button. – Kartheek Jun 25 '15 at 10:06
  • To prevent the text from updating, remove the listener for the radiobutton by setting it null, update the radio button then add back the listener to radio button @AmirHossain – Kartheek Jun 25 '15 at 10:12