我使用此(链接或代码)来存储用户的ID和密码 http://techblogon.com/android-login-registration-screen-with-sqlite-database-example/
问题是当用户登录其帐户时,我想在列表视图中永久存储列表视图项
private static int RESULT_LOAD_IMAGE = 1;
private String currentImageName = "ic_launcher";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_ad_layout);
Button saveButton = (Button) findViewById(R.id.buttonSaveAdd);
saveButton.setOnClickListener(this);
Button buttonaddimage = (Button) findViewById(R.id.buttonAddImage);
buttonaddimage.setOnClickListener(this);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want Create a new Add?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Intent intent = new Intent(Create_adds_Activity.this, Button_mak.class);
startActivity(intent);
}
});
builder.show();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.buttonAddImage:
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
break;
case R.id.buttonSaveAdd:
EditText editTextTitle = (EditText) findViewById(R.id.editTextTitle);
EditText editTextDes = (EditText) findViewById(R.id.editTextDescription);
EditText editTextOwner = (EditText) findViewById(R.id.editTextOwnerName);
EditText editTextOwnerEmail = (EditText) findViewById(R.id.editTextOwnerEmail);
EditText editTextPrice = (EditText) findViewById(R.id.editTextPrice);
//populating data object from the values received
//from view
String title = editTextTitle.getText().toString();
String description = editTextDes.getText().toString();
String ownerName = editTextOwner.getText().toString();
String ownerEmail = editTextOwnerEmail.getText().toString();
String pricce = editTextPrice.getText().toString();
Advertisement object = new Advertisement(title, description,
ownerName, ownerEmail, currentImageName, Integer.parseInt(pricce), 100);
Button_mak.ads.add(object);
this.finish();
break;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView10 = (ImageView) findViewById(R.id.creatae);
imageView10.setImageBitmap(BitmapFactory.decodeFile(picturePath));
currentImageName = ">>>"+picturePath;
}
我使用数组适配器
final Context context = this;
public static ArrayList<Advertisement> ads = new ArrayList<Advertisement>();
答案 0 :(得分:0)
我会狡猾地建议使用SQLite来保存您的数据。 在一开始它可能看起来有点复杂,但是当你习惯它时,它很容易。
这是一个方便的小教程:http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/