Refresh ListView in ImageButton.onClick inside getView off a BaseAdapter

前提是你 提交于 2019-12-13 02:45:11

问题


I have an activity that is generated by a custom BaseAdapter and look like this:

This is the getView off the custom BaseAdapter:

    @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;
}

Basically, the onClick off btnUp and btnDown are self explanatory. The order need to be saved in database too because it will be sent after. The update in dastabase works fine, my problem is: How can I refresh the ListView inside his own BaseAdapter?

I checked this question but without success.


回答1:


I've used BroadcastReceiver to refresh the ListView like this



来源:https://stackoverflow.com/questions/15271608/refresh-listview-in-imagebutton-onclick-inside-getview-off-a-baseadapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!