Na  Jun Yeop
Na Jun Yeop

Reputation: 65

Android ListView Some Questions

I have some questions about ListView. The Post that I've searched doesn't satisfy me.

  1. If I have five list items and call notifyDataSetChanged() method in customAdapter, How many times does getView method called?

  2. I have a checkbox on each list and it must be shown only when the delete button is clicked. The Delete button is created on the Activity Class, and the checkbox is created in the Adapter Class (I mean findViewById). Then how can I handle this? Currently my code changes flag value on Activity Class and call notifyDataSetChanged() method on Adapter Class.

  3. How can I handle UI without call notifyDataSetChanged() method? (I've implemented in this way...)

Sorry about not posting my code.

Upvotes: 0

Views: 159

Answers (1)

Valentun
Valentun

Reputation: 1711

  1. Get view calls every time when item appears at the screen, so in your case it is 5 times.
  2. You can do something like that:

    2.1 Create a public method in your adapter, for example:

    public void setIsDeleteModeEnabled(boolean isEnabled) {
        //Logic here
    }
    

    2.2 In your Activity, when Button is clicked call adapter.setDeleteModeEnabled(true);

3 You should call notifyDataSetChanged() only when dataset is changed. For handling UI events you should:

In list item: you should set onClickListeners in getView();

In Activity : onCreate() method in adapter and call it in Activity's onClicks

Upvotes: 1

Related Questions