我有一个是通过自定义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
是自解释的。 订单需要被保存在数据库中也因为它会被发送之后。 在dastabase更新工作得很好,我的问题是:我怎么能刷新自己的BaseAdapter里面的ListView?
我检查这个问题,但没有成功。