我正在开发Android中与计费相关的APP。我有一个数据库,其中有4列:
ITEMNAME
PRICE
STOCK
ID
ID
列处于自动递增状态
在我的主要活动中,我使用具有5列的表布局,其中我对2列有问题。第二列是ITEMNAME
,第三列是PRICE
。
在ITEMNAME
列上,我使用与数据库链接的自动完成TextView
。每当我在自动完成TextView
中输入商品名称时,我都希望自动在“价格列”中获取价格
这是我向自动完成TextView
添加数据的方法:
public void preparedata2() {
list = new ArrayList<String>();
Cursor res1 = mydb.getAllData1();
if (res1.getCount() == 0) {
Toast.makeText(this, "No data in the database", Toast.LENGTH_SHORT).show();
} else {
while (res1.moveToNext()) {
list.add(res1.getString(1));
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
}
这是我的动态布局代码:
public void onClick(View view) {
tr1 = new TableRow(this);
et6 = new EditText(this);
et6.setText("");
et7 = new AutoCompleteTextView(this);
et7.setAdapter(adapter);
et7.setThreshold(1);
et7.setText("");
et7.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
try {
{
"""" HERE I WANT HELP""""
}
} catch (Exception e) {
Toast.makeText(shopp.this, "Something went wrong 1", Toast.LENGTH_SHORT).show();
}
;
}
});
et8 = new EditText(this);
et9 = new EditText(this);
et10 = new EditText(this);
et8.setText("");
et9.setText("");
et10.setText("");
et6.setBackgroundResource(R.drawable.edittext3);
et6.setGravity(Gravity.CENTER);
et6.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
et7.setBackgroundResource(R.drawable.edittext3);
et7.setGravity(Gravity.CENTER);
et7.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
et8.setBackgroundResource(R.drawable.edittext3);
et8.setGravity(Gravity.CENTER);
et8.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
et9.setBackgroundResource(R.drawable.edittext3);
et9.setGravity(Gravity.CENTER);
et9.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
et10.setBackgroundResource(R.drawable.edittext3);
et10.setGravity(Gravity.CENTER);
et10.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
tr1.addView(et6);
tr1.addView(et7);
tr1.addView(et8);
tr1.addView(et9);
tr1.addView(et10);
t1.addView(tr1);
这是我的SQLite数据检索方法:
public Cursor getAllData1() {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res1 = db.rawQuery("select * from " + Tname, null);
return res1;
}
答案 0 :(得分:-1)
尝试此代码。
public List<MyTableTwo> getMyItems() {
List<MyTableTwo> mySuperList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + USER_TABLE_NAME;
Cursor c = db.rawQuery(selectQuery, null);
if (c != null) {
c.moveToFirst();
while (c.isAfterLast() == false) {
MyTableTwo myTable = new MyTableTwo();
myTable.itemName = (c.getString(c.getColumnIndex("Item_Name")));
myTable.weight = (c.getString(c.getColumnIndex("Weight")));
myTable.mrp = (c.getString(c.getColumnIndex("MRP")));
myTable.barcod = (c.getString(c.getColumnIndex("BARCODE")));
mySuperList.add(myTable);
c.moveToNext();
}
}
return mySuperList;
}
答案 1 :(得分:-1)
Use This Code
public ArrayList<GIF> getGIFName() {
dbHelper.getWritableDatabase();
ArrayList<GIF> gifList = new ArrayList();
String selectQuery = " SELECT * FROM gif_detail ";
Cursor cursor = database.rawQuery(selectQuery, null);
if (cursor.getCount() > 0) {
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
gifList.add(new GIF(cursor.getString(1), false));
}
}
cursor.close();
Log.d("TotalGIF File =", gifList.size() + "");
return gifList;
}