【发布时间】:2012-02-28 00:30:37
【问题描述】:
我正在使用以下内容来填充我的列表视图,并且如果我单击 btn_Delete,我不想显示项目,我已成功从 hasValues 中删除了项目,但它显示了列表视图中的空白项目,
我想从列表中删除这个空白列表视图项。
如果有人知道如何做到这一点,请回复。
谢谢,
private class MyArrayAdapter extends ArrayAdapter
{
private List<HashMap<String, String>> myData = new ArrayList<HashMap<String, String>>();
public MyArrayAdapter(Context context, int textViewResourceId, List<HashMap<String, String>> objects)
{
super(context, textViewResourceId, objects);
context = getContext();
myData = objects;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View v = convertView;
try
{
if(v == null)
{
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.listSomeThing, null);
}
if(hasValues != null && !hasValues.get(DatabaseConstant.key_STATUS).equals("D"))
{
btn_Delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
// delete item from HasValues..
}
}
else
{
v.setVisibility(View.GONE);
}
}
catch (Exception e)
{
Utility.saveExceptionDetails(LogsDetails.this, e);
e.printStackTrace();
}
return v;
}
}
【问题讨论】:
-
我认为这不是为此目的的最佳解决方案。只需尝试设置您的具体条件并增加您在 getView 中的位置数。
标签: android list android-arrayadapter