android 从数据库读取数据显示到界面上
这是我的代码,但显示结果却不对,
//获取游标
database= SQLiteDatabase.openOrCreateDatabase(DBManager.DB_PATH + "/" + DBManager.DB_NAME, null);
Cursor cursorone= database.rawQuery("select _id,barcode,number from t_firstcheckinfo ", null);
if(cursorone.moveToFirst())
{
//创建SimpleCursorAdapter适配器将数据绑定到item显示控件上
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, cursorone,
new String[]{"barcode", "number",}, new int[]{R.id.barcode, R.id.number});
listView.setAdapter(adapter);
//条目点击事件
listView.setOnItemClickListener(new ItemClickListener());
}
}
public class ItemClickListener implements OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
ListView listView = (ListView) parent;
Cursor cursor = (Cursor) listView.getItemAtPosition(position);
String personid = String.valueOf(cursor.getInt(cursor.getColumnIndex("_id")));
Toast.makeText(getApplicationContext(), personid, 1).show();
}
}
}
,其中数量15显示到条码下面去了,是怎么回事呢,麻烦牛人们给看看。 android simplecursoradapter listview 数据库
[解决办法]
建议LZ的R.layout.item采用LinearLayout布局,设置android:orientation="horizontal" ,在布局里面放置条码和数量的TextView,调整位置对齐就可以了。