views:

195

answers:

1

I have ListViewActivity

public class SelectActivity extends ListActivity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_one_of);
        SimpleAdapter adapter = new SimpleAdapter(
            this,
            createChildList(),
            R.layout.select_one_of_childrow, 
            new String[] { KEY_VALUE },
            new int[] { R.id.selectoneof_add_new_item});
        setListAdapter(adapter);
    }
// ...
}

after setListAdapter() calls I would like to execute the following code:

((TextView) getListView().getChildAt(0).findViewById(R.id.selectoneof_add_new_item)).setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ticked, 0);

but getListView().getChildAt(xxx) returns null and I catch NullPointerException. Where should I put mentioned above code-snippet?

A: 

Where should I put mentioned above code-snippet?

Nowhere. Instead, write a custom ListAdapter and customize your rows that way. Here is a free excerpt from one of my books that demonstrates the general technique.

CommonsWare
I don't believe this! I still hope that it can be done simply without writing own/custom ListAdapter
davs
IMHO, "writing own/custom ListAdapter" is simpler and more reliable than what you are proposing.
CommonsWare
... But I don't want to do check during each listView rendering ... I need to do that on once on Activity's start ...
davs
I found that listView.postInvalidate() calls when everything is being invaludated. Is it possible to override this method?
davs
Thank you, guy! I found that when list has big amount of data and I would scroll this list, I have to call "setCompoundDrawablesWithIntrinsicBounds()" for each elements in any case to avoid 'strange' behavior.Sorry I didn't believe to before :)
davs