【慢慢學Android】:10.處理listview長按事件,刪除所選項


listview.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					int position, long id) {
				String item = (String) listview.getItemAtPosition(position);

				SharedPreferences Addresses = getSharedPreferences(FileListenerActivity.PREFS_NAME, 0);
				SharedPreferences.Editor editor = Addresses.edit();
				editor.remove(item);
				editor.commit();
				
				Toast.makeText(getBaseContext(), item + "被刪除了",
						Toast.LENGTH_SHORT).show();
				
				 list.remove(item);
				 adapter.notifyDataSetChanged();

				return true;
			}

		});

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM