Android 在listview中识别已单击项的最佳选项?
在我的应用程序中,我有一个listview和一个创建相册的按钮,通过单击按钮应用程序,一个新项目将添加到listview,通过单击每个listview项目,您可以转到该相册并上传/拍摄照片以供显示 为了在拍摄/拾取后保存和检索照片,我使用SharedPreference保存和检索图像路径。正如您所见,我无法拥有预定义的SharedPreference,因此我使用了我自己创建的方法:在listview中,我创建了这个str字符串,并将其放入一个intent中,它将传递到我的第一个相册页面:Android 在listview中识别已单击项的最佳选项?,android,listview,android-listview,Android,Listview,Android Listview,在我的应用程序中,我有一个listview和一个创建相册的按钮,通过单击按钮应用程序,一个新项目将添加到listview,通过单击每个listview项目,您可以转到该相册并上传/拍摄照片以供显示 为了在拍摄/拾取后保存和检索照片,我使用SharedPreference保存和检索图像路径。正如您所见,我无法拥有预定义的SharedPreference,因此我使用了我自己创建的方法:在listview中,我创建了这个str字符串,并将其放入一个intent中,它将传递到我的第一个相册页面: lis
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
String str = new String("album" + arg2);
Intent intent = new Intent(Albums.this, MainA.class);
intent.putExtra("extra", str);
startActivity(intent);
}
});
通过这种方式,一切都很完美,但当用户删除Lisview中的第二个相册第二项时除外,这会导致第三个相册成为第二个相册,并且由于我使用位置int指定SharedPreference,它将完全销毁
我不知道你是否能理解我的方式,但如果你做到了,我该怎么做才能避免这种情况
这种方式对我来说是最好的方式吗
谢谢
编辑:
正在删除listview项目代码:
public void deletetask(String t){
if (null == itemArrey) {
itemArrey = new ArrayList<String>();
}
itemArrey.remove(t);
//save the task list to preference
b1s = getSharedPreferences("pref", Context.MODE_PRIVATE);
try {
b1s.edit().putString("array", ObjectSerializer.serialize(itemArrey)).commit();
} catch (IOException e) {
e.printStackTrace();
}
}
伙计,这毫无意义。为什么不能使用sql?即使要将SharedReferences用于store,也应创建名为album的对象:
Class album {
private long id;
private String path;
}
然后,在OnItemClickListener上,arg3将是您必须在adapter类的getId上传递的id,创建一个自定义适配器扩展baseAdapter用户相册列表,这并不难。发布发生删除的coe首先尝试替换此行:String str=getIntent.getStringextra@Rod_Algonquin我添加了代码,但我不认为这是问题所在。@Haresh这些不一样吗?我理解逻辑,但将int作为唱片号码传递是行不通的。相反,在内存设备上创建一个应用程序专用的文件夹,并将相册文件夹放入其中。现在,如果相册被删除,只需删除文件夹并用文件夹名称(即相册名称)再次填充列表即可。
Class album {
private long id;
private String path;
}