안드로이드에 사용자 지정 어댑터가 있습니다.이 사용자 지정 어댑터에는 텍스트가있는보기와 텍스트를 삭제하는 단추가 있습니다. 이 모든 잘 작동하고 데이터베이스에서 레코드를 삭제할 수 있지만 목록을 새로 고칠 수 없습니다.커서 어댑터의 ListFragment 내부의 목록보기 업데이트
목록은 작은 다음과 같다 : 다시 내 목록 조각 내부의 메소드를 호출 할 수
QCListFragment frag = (QCListFragment) getSupportFragmentManager().findFragmentById(R.id.listFragment);
어떤 시점에서 :
------------------------------------
text text text text | Delete Button|
------------------------------------
text text text text | Delete Button|
------------------------------------
나의 첫번째 본능이 같은 것을 사용하는 것이 었습니다 -query the list ... 내 어댑터가 조각을 확장하지 않기 때문에이 작업을 수행 할 수 없습니다. 그래서 나는 조각이 데이터가 변경되었음을 알게하는 것이 어렵다는 것을 알고 있습니다.
어쨌든, 나의 마지막 생각은 단지 활동을 재구성하는 것이었지만 나는 그게 아마도 최선의 일이 아니었고 더 나은 방법이 있어야한다고 생각했습니다 ... 나는 그것이 내 마지막 질문처럼 실종 됐어!
(그것이 도움이 될 것입니다 만약 내가 더 많은 코드를 게시 할 수 있습니다) UPDATE : 여기 내 전체 어댑터 클래스
공용 클래스 CalcCursorAdapter는 SimpleCursorAdapter는 필터링 {
private Context mContext;
private ListView mListView;
private int mLayout;
private Cursor mcursor;
protected static class ViewHolder {
protected TextView text;
protected ImageButton button;
private int position;
}
@SuppressWarnings("deprecation")
public CalcCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
{
super(context, layout, c, from, to);
this.mContext = context;
this.mLayout = layout;
this.mcursor = c;
//mListView = .getListView();
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView summary = (TextView)view.findViewById(R.id.calctvPrice);
TextView savings = (TextView)view.findViewById(R.id.calctvSavings);
summary.setText(cursor.getString(cursor.getColumnIndexOrThrow("qcFinalPrice")));
savings.setText(cursor.getString(cursor.getColumnIndexOrThrow("qcSavings")));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.calc_list_item, parent, false);
holder.button = (ImageButton) v.findViewById(R.id.qcbtnDelete);
holder.button.setOnClickListener(deleteButton);
holder.position = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
bindView(v, context, cursor);
v.setTag(holder);
return v;
}
private OnClickListener deleteButton = new OnClickListener() {
public void onClick(View v){
View view = (View) v.getParent();
ViewHolder holder = (ViewHolder) view.getTag();
int position = holder.position;
DbHelper mDbHelper;
mDbHelper = new DbHelper(mContext);
mDbHelper.open();
mDbHelper.deleteCalc(position);
mDbHelper.close();
String test = Integer.toString(position);
Toast.makeText(mContext.getApplicationContext(), test, Toast.LENGTH_SHORT).show();
notifyDataSetChanged();
}
};
public long qcItemId(int position) {
return position;
}
}
하나를 구현 확장 도움이 많이 감사합니다!
감사합니다.
notifyDatasetChanged() 메소드를 시도 했습니까? – Varundroid
조각이 클릭을 처리하지 못한다. 어댑터가 클릭 한 단추가 목록 안에 있기 때문입니다. 및 의미 (적어도 내 지식) 어댑터 안쪽에 있기 때문에 adapter.notifyDatasetChanged() 호출 할 수 없습니다 ... – Klaven
내 대답 좀 봐 및 지금 전화 할 수 있으면 알려주세요 notifyDatasetChanged() 메소드. 우리는 최선을 다해 당신을 도울 것입니다. – Varundroid