我有一个由自定义 BaseAdapter 生成的活动,如下所示:
这是getView
关闭自定义 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
是不言自明的。订单也需要保存在数据库中,因为它会在之后发送。数据库中的更新工作正常,我的问题是:如何刷新他自己的 BaseAdapter 中的 ListView?
我检查了这个问题,但没有成功。