首页 > 代码库 > listview getChiildAt结果为空

listview getChiildAt结果为空



mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,

int position, long id) {


for (int i = 0; i < mListView.getCount(); i++) {


View callLogView = mListView.getChildAt(i);


mRelativeLayout = (LinearLayout) callLogView
.findViewById(R.id.myShow);
if (i == position) {
if (mRelativeLayout.getVisibility() == View.GONE) {
mRelativeLayout.setVisibility(View.VISIBLE);
} else {
mRelativeLayout.setVisibility(View.GONE);
}
} else {
mRelativeLayout.setVisibility(View.GONE);
}
}
}

});




代码如上,最后得到的callLogView 是空的,我以前这个就可以得到position所对应的item,其实getChildAt ( int position ) 方法中position指的是当前可见区域的第几个元素。

  那要得到position所对应的item咋办? View itemView = listview.getAdapter().getView(position, null, listview);  这样就能得到l