我在ListView关闭时从ListView获取项目时遇到问题。如果我向下滚动并点击下一步,则顶部项目返回null 。如果我向上滚动,则底部项目返回null。
我知道ListView会动态创建视图,因此可以将项目移出屏幕吗?
public void onNextClick(View w){
Intent i = new Intent(this, homeActivity.class);
for(int position = 0; position < expandableLayoutListView.getAdapter().getCount(); position++)
{
try {
Hub temp = ((Hub) expandableLayoutListView.getAdapter().getItem(position));
System.out.println("Position " + position);
System.out.println("Other position " + (position - expandableLayoutListView.getFirstVisiblePosition()));
ExpandableLayoutItem expandableLayout = (ExpandableLayoutItem)
expandableLayoutListView.getChildAt(position - expandableLayoutListView.getFirstVisiblePosition())
.findViewWithTag(ExpandableLayoutItem.class.getName());
JoinedHub hub = new JoinedHub(temp.name);
if(((CheckBox) expandableLayout.findViewById(R.id.checkBox1)).isChecked())
hub.addToSubHubs( ((CheckBox) expandableLayout.findViewById(R.id.checkBox1)).getText().toString() );
if(((CheckBox) expandableLayout.findViewById(R.id.checkBox2)).isChecked())
hub.addToSubHubs(((CheckBox) expandableLayout.findViewById(R.id.checkBox2)).getText().toString());
if(((CheckBox) expandableLayout.findViewById(R.id.checkBox3)).isChecked())
hub.addToSubHubs(((CheckBox) expandableLayout.findViewById(R.id.checkBox3)).getText().toString());
Log.d("Debugging position", temp.getName() + " " + position);
if(!hub.subHubs.isEmpty()){
joinedHubs.add(hub);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Log.d("Debugginggg", joinedHubs.toString());
startActivity(i);
}