刷新的ListView在ImageButton.onClick内getView掀起了BaseAdapter [英] Refresh ListView in ImageButton.onClick inside getView off a BaseAdapter

查看:163
本文介绍了刷新的ListView在ImageButton.onClick内getView掀起了BaseAdapter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是通过自定义BaseAdapter产生,并期待这样一个活动:

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

这是 getView 关闭自定义BaseAdapter:

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

基本上,的onClick 关闭 btnUp btnDown 不言自明。顺序需要被保存在数据库中也因为它会被后发送。在dastabase更新工作得很好,我的问题是:我怎么能刷新自己的BaseAdapter里面的ListView

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?

我检查<一href=\"http://stackoverflow.com/questions/12685418/how-to-refresh-listview-using-getview-of-baseadapter-on-image-clickevent\">this的问题,但都没有成功。

I checked this question but without success.

推荐答案

我用广播接收器刷新的ListView

这篇关于刷新的ListView在ImageButton.onClick内getView掀起了BaseAdapter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆