다이알로그를 띄어서 사용자가 입력했던 정보들을 보여주고 수정 or 삭제가 가능하게 하고싶은데요...
제가 cursor adapter을 사용해서 리스트뷰를 받아왔는데 dialog에도 그런방법으로 받아오려하는데 잘안되네요 ㅠ.ㅠ 혹시 관련된 예제소스 공유해주실수있으신가요..?ㅠㅠ
이렇게 adpater자바클래스를 따로 생성했고용 그뒤에 메인액티비티에 어댑터를 리스트뷰에 붙였어요!
public class DBAdapter extends CursorAdapter {
public DBAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ImageView image = (ImageView) view.findViewById(R.id.image_view);
final TextView name = (TextView) view.findViewById(R.id.textname);
final TextView date = (TextView) view.findViewById(R.id.textdate);
TextView id1 = (TextView) view.findViewById(R.id.id_row);
image.setImageResource(R.drawable.cake);
name.setText(cursor.getString(cursor.getColumnIndex("name")));
date.setText(cursor.getString(cursor.getColumnIndex("date")));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.listviewitem, parent, false);
return v;
}
}
근데 저 아이템 onClick메소드에서 오류가 발생해서 앱이꺼져요 ㅠ.ㅠ 디비에서 가져오는방법이 잘못된거같은데 도와주세용!!ㅠㅠㅠ
mListView = (ListView) findViewById(R.id.listview);
dbmanager = new DBManager(this);
selectDB();
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
cursor.moveToPosition(position);
AlertDialog.Builder alertDlg = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
alertDlg.setView(inflater.inflate(R.layout.custom_dialog, null));
final TextView name = (TextView) v.findViewById(R.id.dialog_name);
final TextView date = (TextView) v.findViewById(R.id.dialog_date);
sqlitedb = dbmanager.getReadableDatabase();
sql = "SELECT * FROM customers;";
String str = cursor.getString(cursor.getColumnIndex("name"));
String dia_date = cursor.getString(cursor.getColumnIndex("date"));
name.append(":"+str);
// date.append(":"+dia_date);
Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
Log.e("tag", "warning message");
alertDlg.setPositiveButton("확인", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); // AlertDialog를 닫는다.
}
});