我有一个列表视图,点击后会打开,但不会显示有关该列表视图项的详细信息。列表视图的数据由类输入到sqlite数据中,并由另一个类从sqlite数据库中提取。不确定我在哪个课程出错时应该在点击列表视图时拔出数据。我没有足够的pont来发布相关xml文件的图像,但是onClick方法在
之下列表视图:
@覆盖
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getApplicationContext(), "clicked on :" + arg2, Toast.LENGTH_SHORT).show();
Intent updateDeleteLoginInfo = new Intent (this, UpdateDeleteLoginList.class);
LoginDetails clickedObject = loginArrayList.get(arg2);
Bundle loginBundle = new Bundle();
loginBundle.putString("clickedwebSite",clickedObject.getsName());
loginBundle.putString("clickedwebAddress",clickedObject.getwUrl());
loginBundle.putString("clickeduserName",clickedObject.getuName());
loginBundle.putString("clickedpassWord",clickedObject.getpWord());
updateDeleteLoginInfo.putExtras(loginBundle);
startActivity(updateDeleteLoginInfo);
更新课程:
@覆盖
public void onClick(View v){
loginSitetext = sName.getText().toString();
loginAddresstext = wUrl.getText().toString();
loginUsertext = uName.getText().toString();
loginpassWordtext = pWord.getText().toString();
LoginDetails loginDetails = new LoginDetails();
loginDetails.setsName(bundledWebSite);
loginDetails.setwUrl(bundledWebAddress);
loginDetails.setuName(bundledUserName);
loginDetails.setpWord(bundledPassWord);
if(v.getId()==R.id.rucBttn){
finish();
}else if(v.getId()==R.id.ruuBttn){
updateLoginDetails(loginDetails);
}else if(v.getId()==R.id.rudBttn){
deleteLoginDetails(loginDetails);
}
}
private void updateLoginDetails(LoginDetails loginDetails){
dataStore androidOpenDbHelper = new dataStore(this);
SQLiteDatabase sqliteDatabase = androidOpenDbHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(dataStore.COLUMN_NAME_SITE, loginSitetext);
contentValues.put(dataStore.COLUMN_NAME_ADDRESS, loginAddresstext);
contentValues.put(dataStore.COLUMN_NAME_USERNAME, loginUsertext);
contentValues.put(dataStore.COLUMN_NAME_PASSWORD, loginpassWordtext);
String[] whereClauseArgument = new String[1];
whereClauseArgument[0]= loginDetails.getsName();
System.out.println("whereClauseArgument[0] is :" + whereClauseArgument[0]);
sqliteDatabase.update(dataStore.TABLE_NAME_INFOTABLE, contentValues, dataStore.COLUMN_NAME_SITE+"=?", whereClauseArgument);
sqliteDatabase.close();
finish();
}
private void deleteLoginDetails(LoginDetails deleteLoginDetails){
dataStore androidOpenDbHelper = new dataStore(this);
SQLiteDatabase sqliteDatabase = androidOpenDbHelper.getWritableDatabase();
String[] whereClauseArgument = new String[1];
whereClauseArgument[0] = deleteLoginDetails.getsName();
sqliteDatabase.delete(dataStore.TABLE_NAME_INFOTABLE,dataStore.COLUMN_NAME_SITE+"=?", whereClauseArgument);
sqliteDatabase.close();
finish();
答案 0 :(得分:0)
您可以使用notifyDataSetChanged()函数来实现更新listView。
或
每次更新需要更新的列表时都会分配一个新适配器。
答案 1 :(得分:0)
在另一个类的whereClauseArgument中找不到'C'。资本化之后,每件事情都应该有效。