nyt23
nyt23

Reputation: 53

ListView getChildAt(i) gives null

I have a listview with with custom Layout. ListView items come from a separate xml document. The listview renders properly, now I want to access the textview and the editview which is in that listview, and I want to change the value of that dynamically. I tried it using list.getChildAt(i) but it gives me a null view. So how can I access the textviews?

ListView list=(ListView)findViewById(R.id.list); 
adapter=new LazyAdapter(this,5,R.layout.layout_id); 
list.setAdapter(adapter); 
for (int j = 0; j < list.getCount(); j++) { 
    View v = list.getChildAt(j);
    EditText text = (EditText) v.findViewById(R.id.textview1);
    text.setText("Hello");
} 

Ok I tried a lot and found that list.getChildAt(i) gives me value on onClickListener(). I want to get that value after the list render in onCreate() method. So how can i get the list value immediately of list render?

Upvotes: 0

Views: 608

Answers (1)

Angelo.Hannes
Angelo.Hannes

Reputation: 1729

As you said you used a custom Layout, did you write your own Adapter? If so, you properly have to override the getChildAt-method. Hence you have to manage the model on your own.

Upvotes: 1

Related Questions