1

タイトルはほとんどそれをすべて言います。シンプルなアダプターと、リストビュー項目に存在する行数に基づいて変化する xml レイアウトによってリストビューにデータが取り込まれています。アクティビティ内の項目の 1 つにデータを追加すると、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 に答える