【问题标题】:Refresh ListView in ImageButton.onClick inside getView off a BaseAdapter从 BaseAdapter 的 getView 中刷新 ImageButton.onClick 中的 ListView
【发布时间】:2013-03-07 12:45:24
【问题描述】:

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

这是自定义 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 是不言自明的。订单也需要保存在数据库中,因为它会在之后发送。数据库中的更新工作正常,我的问题是:如何刷新他自己的 BaseAdapter 中的 ListView?

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

【问题讨论】:

    标签: android listview imagebutton listviewitem baseadapter


    【解决方案1】:

    我用BroadcastReceiver 刷新ListView 就像this 一样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多