1

标题基本概括了所有内容。我有一个由简单适配器填充的列表视图和一个 xml 布局,该布局根据列表视图项中存在的行数而变化。当我将数据添加到活动中的一项时,调用 notifyondatasetchanged 不会更新列表,但如果我退出活动并返回一切看起来应该是这样。当我刷新适配器时,getview 也会更新,我需要做什么?

    public AlarmListAdapter(Context context, ArrayList<HashMap<String, String>> list, int textViewResourceId, String[] fields, int[] textViewId) {
    super(context, list, textViewResourceId, fields, textViewId);
    this.list = list;
    this.context = context;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View v = convertView;
if (v == null) {
    LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = vi.inflate(R.layout.alarm_list_item, null);
}


if(list.get(position).get("alert") == null){    
    v.findViewById(R.id.ListViewItemSub).setVisibility(View.GONE);
}

return super.getView(position, convertView, parent);

}


public void forceReload(){
    notifyDataSetChanged();
}

从我的活动中的弹出窗口调用 notifyondatasetchanged。该按钮的代码如下所示:

        addCustomAlertButton = (Button)pView.findViewById(R.id.AddCustomAlertButton);
    addCustomAlertButton.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            arrayList.get((int) customAlertId).setAlertDialog(customAlertInput.getText().toString());
            Toast.makeText(EditAlarmsActivity.this, "Custom Alert Added", Toast.LENGTH_SHORT).show();
            updateListArray();
            pw.dismiss();
        }
4

1 回答 1

0

你可以试试setListAdapter(yourAdapter);

或者listview.requestLayout();

如果这些不起作用,那么您也可以尝试通过滚动刷新列表视图,因为一旦滚动列表视图就会调用 getView() 函数。

于 2011-07-16T09:04:25.390 回答