0
我想开发在android系统SQlite的一个小项目获取数据..Android的ListView控件从SQLite数据库
我想存储EN员工信息数据库.. 的字段名称,城市,邮件ID和电话号码..
然后,我想在列表视图中获取数据..它会显示员工名称.. 当我点击名称(另一个意图)它会显示该名称的所有信息。
我已创建DB辅助类的,我可以存储information..But我无法检索由name..can任何数据库帮我?????
public class DBHelper extends SQLiteOpenHelper {
static final String DATABASE = "contactapp.db";
static final int VERSION = 1;
static final String TABLE = "contact";
static final String C_ID = "_id";
static final String C_ENAME = "ename";
static final String C_city = "city";
static final String C_phno = "ph_no";
public DBHelper(Context context) {
super(context, DATABASE, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE + " (" + C_ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + C_ENAME + " text, "
+ C_city + " text, " + C_phno + " integer)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("Drop table " + TABLE);
onCreate(db);
}
}
和存储姓名,城市和SQLite数据库电话号码management.java ..
public class Management extends Activity {
EditText tname,tcity,tph_no;
Button button1;
DBHelper helper;
SQLiteDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.management);
helper = new DBHelper(this);
tname = (EditText) findViewById(R.id.tname);
tcity = (EditText) findViewById(R.id.tcity);
tph_no = (EditText) findViewById(R.id.tph_no);
button1=(Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Context context = getApplicationContext();
int s2=Integer.parseInt(tph_no.getText().toString());
ContentValues values = new ContentValues();
values.put(DBHelper.C_ENAME, tname.getText().toString());
values.put(DBHelper.C_city, tcity.getText().toString());
values.put(DBHelper.C_phno, s2);
db = helper.getWritableDatabase();
db.insert(DBHelper.TABLE, null, values);
db.close();
Toast.makeText(context, "Employee Added Successfully",
Toast.LENGTH_LONG).show();
}
});
}
}
现在我想要检索/取只作为list..when我点击它命名为会去另一个意图,将显示名称(再次),城市和电话号码的名字..
然后发布一些有用的代码。 –
份额无论你迄今所做的 –
的,你需要自定义'ListView'和'Adapter'来说,这[链接](http://androidtuts4u.blogspot.in/2013/02/android-list-view-using-定制adapter.html)将帮助你.. – Akshay