我有一个AdapterView
显示分隔不同列表类别的列表和标题。该列表由带有用户输入的 SQLite 数据库填充。到目前为止,一切正常。
当标题的类别中没有项目时,我想删除标题。代码如下:
public View getView(int position, View convertView, ViewGroup parent)
{
int viewType = getItemViewType(position);
if (viewType == TYPE_NORMAL)
{
// If the convertView is a textview (group), ignore it
if (convertView instanceof TextView)
{
convertView = null;
}
final int mapCursorPos = getInteralItemPosition(position);
return super.getView(mapCursorPos, convertView, parent);
}
else
{
// Check if it's a text view
TextView text;
if (convertView == null || !(convertView instanceof TextView))
{
((ListView) parent).setDivider(null);
((ListView) parent).setDividerHeight(0);
text = (TextView) inflater.inflate(R.layout.main_list_group, parent, false);
}
else
{
text = (TextView) convertView;
}
final String group = groupsIndexer.get(position).getName(resources);
//Code to hide menu title.
text.setText(group);
text.setVisibility(View.INVISIBLE);
myCursor = getCursor();
initCols(myCursor);
myCursor.moveToFirst();
while (myCursor.isAfterLast() == false)
{
String groupCursor = getGroup(myCursor).getName(resources);
if (groupCursor == group)
{
text.setHeight(12);
text.setPadding(20, 10, 0, 10);
text.setVisibility(View.VISIBLE);
}
myCursor.moveToNext();
}
return text;
}
}
因此,如您所见,我首先将文本设置为不可见,然后查询数据库以检查其特定类别中是否有任何项目,以及是否将可见性设置为可见。
但是,当返回时,该方法似乎忽略了 while 循环中的任何内容。getView()
不能像这样单独格式化每个 textview 对象吗?
提前致谢。