I have in a layout with a ListView. In onCreate() I set Adapter to the ListView, to show the list, this work fine.
But I try to get access to a ItemView of the listview like this.
https://stackoverflow.com/a/2679284/1149815
public class MainActivity extends Activity {
private ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView)findViewById(R.id.listView1);
listView.setAdapter(new TestAdapter(this, getLayoutInflater()));
int wantedPosition = 1;
int firstPosition = listView.getFirstVisiblePosition() - listView.getHeaderViewsCount(); // This is the same as child #0
int wantedChild = wantedPosition - firstPosition;
if (wantedChild < 0 || wantedChild >= listView.getChildCount()) {
Log.w("--", "Unable to get view");
}
View wantedView = listView.getChildAt(wantedChild);
Log.i("--","" +( wantedView == null) + "");
}}
I need access to wantedView, can someone help me?
LogCat says:
--"Unable to get view
-- true
Thanx