public
class
Food_Info
extends
Activity {
private
DBManager dbm;
int
temp =
0
;
String name, info, ingredients, calorie, time, process, tip;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.food_info);
LinearLayout layout = (LinearLayout)findViewById(R.id.foods);
try
{
dbm =
new
DBManager(
this
);
SQLiteDatabase db = dbm.getWritableDatabase();
Intent it = getIntent();
Bundle bundle = it.getExtras();
int
position = bundle.getInt(
"food_position"
);
Cursor cursor = db.rawQuery(
"select Name, Info, Ingredients, Calorie, Time, Process, Tip from FoodDataBase"
,
null
);
while
(cursor.moveToNext()) {
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"
));
}
}
TextView food_info1 =
new
TextView(
this
);
food_info1.append(name);
food_info1.setTextSize(
80
);
food_info1.setTextColor(Color.rgb(
255
,
255
,
0
));
layout.addView(food_info1);
TextView food_info2 =
new
TextView(
this
);
food_info2.append(
"설명 : "
+ info +
"\n"
);
food_info2.append(
"재료 : "
+ ingredients +
"\n"
);
food_info2.append(
"칼로리 : "
+ calorie +
"\n"
);
food_info2.append(
"시간 : "
+ time +
"\n"
);
food_info2.append(
"요리과정 : "
+ process +
"\n"
);
food_info2.append(
"팁 : "
+ tip +
"\n"
);
food_info2.setTextSize(
20
);
layout.addView(food_info2);
cursor.close();
dbm.close();
}
catch
(SQLiteException e) {
}
}
디비
package
com.andro;
import
android.content.Context;
import
android.database.sqlite.SQLiteDatabase;
import
android.database.sqlite.SQLiteOpenHelper;
public
class
DBManager
extends
SQLiteOpenHelper{
private
static
String DB_NAME =
"FoodDataBase"
;
public
DBManager(Context context){
super
(context, DB_NAME,
null
,
1
);
}
@Override
public
void
onCreate(SQLiteDatabase db){
db.execSQL(
"create table FoodDataBase (Number integer primary key, Name varchar, Info text, Ingredients varchar,"
+
"Calorie varchar, Time varchar, Process text, Tip varchar);"
);
}
@Override
public
void
onUpgrade(SQLiteDatabase db,
int
oldVersion,
int
newVersion) {
}
}
리스트 아이템 선택시.
list.setOnItemClickListener(
new
OnItemClickListener() {
public
void
onItemClick(AdapterView<?> parent, View v,
int
position,
long
id) {
Intent intent =
new
Intent(ListActivity.
this
, Food_Info.
class
);
intent.putExtra(
"food_position"
, position);
startActivity(intent);
}
});
}