1
我使用sharedpreferences將列表視圖中的數據傳遞給另一個列表視圖。我可以寫項目,我不能刪除它們中的一個項目。我沒有錯誤,但我沒有結果。我無法從列表視圖中刪除項目
MyActivity
final DataProvider[] providers = gson.fromJson(jsonurun, DataProvider[].class);
final List<DataProvider> list = Arrays.asList(providers);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
final DataProvider dataProvider = (DataProvider) adapterView.getItemAtPosition(i);
AlertDialog.Builder builder = new AlertDialog.Builder(Listele1.this);
builder.setMessage("Silinsin mi ?")
.setCancelable(false)
.setPositiveButton("EVET", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
List<DataProvider> list1 = new ArrayList<DataProvider>(list);//list from 2nd line
list1.remove(dataProvider);
prefAdapter.notifyDataSetChanged();
prefAdapter.notifyDataSetInvalidated();
}
})
我的自定義適配器是PrefAdapter
List<DataProvider> list ;
public PrefAdapter(@NonNull Context context, List<DataProvider> list) {
super(context, R.layout.child_layout,list);
this.list = list;
}
static class LayoutHandler{
TextView ad,fiyat;
}
@Override
public void add(DataProvider dataProvider) {
super.add(dataProvider);
notifyDataSetChanged();
}
@Override
public void remove(DataProvider object) {
super.remove(object);
notifyDataSetChanged();
}
如果我只是寫'list.remove(dataProvider)',我從這一行得到'java.lang.UnsupportedOperationException'錯誤信息 –
非常感謝你的幫助:) –