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);
}
}
}
});
如題,代碼以附上,我現在想做的事是在點擊一項ListView後顯示出一個布局,而其它項的ListView隱藏,但在超過 mListView.getChildCount()後會出現空指針,求解!
看來,沒有一個十全十美的辦法,我采用一個實用的方法,使用mListView.getChildCount()循環,然後再寫個滑動監聽事件,滑動時再隱藏控件。