Pergunta

I'm using a ListView that has within CheckedTextView. To change the CheckedTextView box (checked / unchecked), I'm using this method:

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);

    ...

        SoundDialog.Builder alert;
        v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        switch (soundPreference.getType()) {
        case BOOLEAN:
            CheckedTextView checkedTextView = (CheckedTextView) v;

            if (checkedTextView.isChecked()){
                checkedTextView.setCheckMarkDrawable(R.drawable.ic_blue);
            } else {
                checkedTextView.setCheckMarkDrawable(R.drawable.ic_red);
            }

            boolean checked = !checkedTextView.isChecked();
            ((CheckedTextView) v).setChecked(checked);

            ...

This works but has a problem, the method executes within the listview listener (onListItemClick (ListView l, View v, int position, long id) {...) When you enter the activity, the CheckedTextView has its default image until you click on the item and executes the method.

How I can implement this method in the onCreate (if (checkedTextView.isChecked ()) {...) if the CheckedTextView is created inside the onListItemClick?

I searched a lot but can not find answer.

I appreciate any help

thanks in advance.

Foi útil?

Solução

You have to determine whether CheckedTextView has to be checked or not in the getView() method of your ListAdapter class. Code in Listeners will be executed only when that particular Listener event is generated until and unless Listener code is not executed even you write in onCreate() method.

and sorry for my english .....

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top