在ImageButton.on中刷新ListView,从getAdapter中取出getView

时间:2013-03-07 12:45:24

标签: android listview imagebutton listviewitem baseadapter

我有一个由自定义BaseAdapter生成的活动,如下所示:

enter image description here

这是自定义BaseAdapter的getView

    @Override
public View getView(int position, View view, ViewGroup parent) {
    final Visita visita = getItem(position);

    view = mInflater.inflate(R.layout.visita_item, null); //The ListView Item

    ImageButton btnUp, btnDown;
    btnUp = (ImageButton)view.findViewById(R.id.visita_btn_move_up);
    btnDown = (ImageButton)view.findViewById(R.id.visita_btn_move_down);

    btnUp = (ImageButton) view.findViewById(R.id.visita_btn_move_up);
    if (position != 0) {// First item can't have the button up
        btnUp.setBackgroundResource(R.drawable.ic_arrow_up);
    }

    btnDown = (ImageButton) view.findViewById(R.id.visita_btn_move_down);
    if (position != visitas.size() - 1) {// Last item can't have the button down
        btnDown.setBackgroundResource(R.drawable.ic_arrow_down);
    }

    final DatabaseAdapter adapter = new DatabaseAdapter(context);

    btnUp.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Moving UP");

            ContentValues values = new ContentValues();
            valores.put(DatabaseHelper.VISITA_COLS[5], visita.order - 1);
            String where = "ordem=?";
            String[] whereArgs = {String.valueOf(visita.order)};
            Log.d(TAG, "ID: " + adapter.atualizar(valores, where, whereArgs, DatabaseHelper.TB_VISITA));

                  // I should refresh the ListView now
        }
    });

    btnDown.setOnClickListener(new OnClickListener( ) {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Movind DOWN");

             //Here i should need the same, update the order in database and after refresh the ListView
        }
    });

    return view;
}

基本上,onClick关闭btnUpbtnDown是不言自明的。订单也需要保存在数据库中,因为它将在之后发送。 dastabase中的更新工作正常,我的问题是:如何在自己的BaseAdapter中刷新ListView?

我查了this个问题,但没有成功。

1 个答案:

答案 0 :(得分:0)

我已使用BroadcastReceiver刷新ListView this