public class ListActivity extends Activity{
private static String[] food = {"누룽지", "참치김치찌게", "카레라이스", "죽", "즉석떡볶이", "찜닭"};
private DBManager dbm;
String name, info, ingredients, calorie, time, process, tip;
ArrayAdapter<String> adapter;
ArrayList<String> foodlist;
ListView list;
EditText foodnameText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bt1_activity);
dbm = new DBManager(this);
final SQLiteDatabase db = dbm.getWritableDatabase();
foodnameText = (EditText)findViewById(R.id.foodname);
foodlist = new ArrayList<String>();
foodlist.addAll(Arrays.asList(food));
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, foodlist);
list = (ListView)findViewById(R.id.list);
list.setAdapter(adapter);
Button addButton = (Button)findViewById(R.id.add);
addButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
foodlist.add(0, foodnameText.getText().toString());
adapter.notifyDataSetChanged();
}
});
/* 리스트뷰 롱클릭시 삭제 */
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> parent, View view,
final int position, long id) {
AlertDialog diaBox = new AlertDialog.Builder(ListActivity.this)
.setTitle("Delete")
.setMessage("Really Delete?")
.setIcon(R.drawable.ic_launcher)
.setPositiveButton("no", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
foodlist.remove(position);
list.clearChoices();
adapter.notifyDataSetChanged();
}
})
.setNegativeButton("yes", null)
.create();
diaBox.show();
return false;
}
});
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
try {
Cursor cursor = db.rawQuery("SELECT * FROM FoodDataBase ", null);
while (cursor.moveToNext()) {
//선택한 아이템과 커서의 위치가 일치할때 해당 _id값을 temp로 가져옴(아 이거땜에 디지는줄아랐네)
if(cursor.getPosition() == position) {
name = cursor.getString(cursor.getColumnIndex("Name"));
info = cursor.getString(cursor.getColumnIndex("Info"));
ingredients = cursor.getString(cursor.getColumnIndex("Ingredients"));
calorie = cursor.getString(cursor.getColumnIndex("Calorie"));
time = cursor.getString(cursor.getColumnIndex("Time"));
process = cursor.getString(cursor.getColumnIndex("Process"));
tip = cursor.getString(cursor.getColumnIndex("Tip"));
}
}
Intent intent = new Intent(ListActivity.this, Food_Info.class);
intent.putExtra("NAME", name);
intent.putExtra("INFO", info);
intent.putExtra("INGREDIENTS", ingredients);
intent.putExtra("CALORIE", calorie);
intent.putExtra("TIME", time);
intent.putExtra("PROCESS", process);
intent.putExtra("TIP", tip);
startActivity(intent);
cursor.close();
}catch(SQLiteException e) {
Toast toast = Toast.makeText(ListActivity.this, "예외처리 되었습니다.", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
toast.show();}
}
});
}
계속 NULL값만 받아오는 이유를 모르겟습니다.
테이블 작성도 했고 데이터베이스 폴더안에 모셔놓기도 했습니다.