안드로이드 개발 질문/답변
(글 수 45,052)
public class ManagerTrackEntry extends ManagerTracker {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.managerentry);
// Fill AutoComplete word list from database
fillAutoCompleteFromDatabase();
// Handle Save Button
final Button savePet = (Button) findViewById(R.id.ButtonSave);
savePet.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
final EditText SITE1 = (EditText) findViewById(R.id.EditTextSITE);
final EditText ID1 = (EditText) findViewById(R.id.EditTextID);
final EditText PWD1 = (EditText) findViewById(R.id.EditTextPWD);
// Save new records
SQLiteDatabase db = mDatabase.getWritableDatabase();
db.beginTransaction();
try {
// check if species type exists already
long rowId = 0;
String strID = ID1.getText().toString()
.toLowerCase();
long rowpwd = 0;
String strPWD = PWD1.getText().toString()
.toLowerCase();
// SQL Query
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
queryBuilder.setTables(ID.ID_TABLE_NAME);
queryBuilder.appendWhere(ID.ID_TYPE_NAME + "='"
+ strID + "'");
// run the query
Cursor c = queryBuilder.query(db, null, null, null, null,
null, null);
if (c.getCount() == 0) {
// add the new type to our list
ContentValues typeRecordToAdd = new ContentValues();
typeRecordToAdd.put(ID.ID_TYPE_NAME, strID);
rowId = db.insert(ID.ID_TABLE_NAME,
ID.ID_TYPE_NAME, typeRecordToAdd);
ContentValues typeRecordToAdd1 = new ContentValues();
typeRecordToAdd1.put(PWD.PWD_TYPE_NAME, strPWD);
rowpwd = db.insert(PWD.PWD_TABLE_NAME, PWD.PWD_TYPE_NAME, typeRecordToAdd1);
} else {
c.moveToFirst();
rowId = c.getLong(c.getColumnIndex(ID._ID));
rowpwd = c.getLong(c.getColumnIndex(PWD._ID));
}
c.close();
// Always insert new pet records, even if the names clash
ContentValues ManagerRecordToAdd = new ContentValues();
ManagerRecordToAdd.put(SITE.SITE_NAME, SITE1.getText()
.toString());
ManagerRecordToAdd.put(SITE.ID_TYPE_ID, rowId);
db.insert(SITE.SITE_TABLE_NAME, SITE.SITE_NAME,
ManagerRecordToAdd);
ManagerRecordToAdd.put(SITE.PWD_TYPE_ID, rowpwd);
db.insert(SITE.SITE_TABLE_NAME, SITE.SITE_NAME,
ManagerRecordToAdd);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
// reset form
SITE1.setText(null);
ID1.setText(null);
PWD1.setText(null);
db.close();
} });
// Handle Go to List button
final Button gotoList = (Button) findViewById(R.id.ButtonShowManagers);
gotoList.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Go to other activity that displays pet list
Intent intent = new Intent(ManagerTrackEntry.this, ManagerList.class);
startActivity(intent);
}
});
}
// This method fills the AutoCompleteTextView data adapter with pet types from the database
// In this case, we are using a manual method of mapping Cursor data to
// an ArrayAdapter which we then use in the AutoCompelteTextView
// We show you this method to illustrate how you can use a simple array to seed the AutoText.
// Normally for ListViews and TextViews, you'd just use a SimpleCursorAdapter or a CursorAdapter.
// Unfortunately with AutoCompletTextView, those adapter/view pairings enforce the "value" to the chosen auto-complete string
// to be the id of the item, instead of the string itself, so it doesn't work quite as one would like by default.
// The more appropriate way to handle this is using data-binding, which involves implementing:
// SimpleCursorAdapter.CursorToStringConverter and a FilterQueryProvider is shown in the sample app called MediaPetTracker
void fillAutoCompleteFromDatabase()
{
SQLiteDatabase db = mDatabase.getReadableDatabase();
Cursor c = db.query(ID.ID_TABLE_NAME, new String[] {ID.ID_TYPE_NAME}, null, null,
null, null, ID.DEFAULT_SORT_ORDER);
int iNumberOfSpeciesTypes = c.getCount();
String astrAutoTextOptions[] = new String[iNumberOfSpeciesTypes];
if((iNumberOfSpeciesTypes > 0) && (c.moveToFirst()))
{
for(int i = 0; i < iNumberOfSpeciesTypes; i++)
{
astrAutoTextOptions[i] = c.getString(c.getColumnIndex(ID.ID_TYPE_NAME));
c.moveToNext();
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
astrAutoTextOptions);
AutoCompleteTextView text = (AutoCompleteTextView) findViewById(R.id.EditTextID);
text.setAdapter(adapter);
}
c.close(); db.close(); } }
이게 pet_tracker 를 고친.
넣는부분이 잘못되었다는 가정하에..
entry 부분의 고친소스입니다..
전 아무리 봐도 ..ㅠㅠ 아는게 별로 없는지라 잘 못찾겠네요.. 빠진부분이나 덜 고쳐진곳이 있는지요.ㅠ ㅠ
private ManagerDatabase() {}
// SITE table
public static final class SITE implements BaseColumns {
private SITE() {}
public static final String SITE_TABLE_NAME = "table_SITE";
public static final String SITE_NAME = "site_name";
public static final String ID_TYPE_ID = "id_name_id";
public static final String PWD_TYPE_ID = "pwd_name_id";
public static final String DEFAULT_SORT_ORDER = "site_name ASC";
}
// ID Type table
public static final class ID implements BaseColumns {
private ID() {}
public static final String ID_TABLE_NAME = "table_ID";
public static final String ID_TYPE_NAME = "id_name";
public static final String DEFAULT_SORT_ORDER = "id_name ASC";
}
// PWD Type table
public static final class PWD implements BaseColumns {
private PWD() {}
public static final String PWD_TABLE_NAME = "table_PWD";
public static final String PWD_TYPE_NAME = "pwd_name";
public static final String DEFAULT_SORT_ORDER = "pwd_name ASC";
}
}
이부분은 DB 부분..
발생하는 문제는

이렇게 PWD 테이블만 첫번째 값만을 불러온다는겁니다..ㅠ ㅠ
(첫번째 들어간 값..)
다른테이블은 넣은대로 나오구요 ㅠㅠ



