public class MainActivity extends ActionBarActivity {
ListView listview;
String[] subjects = new String[] {"Android","PHP","Blogger","WordPress","SEO"};
List<String> subject_list;
ArrayAdapter<String> arrayadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ListView)findViewById(R.id.listView1);
subject_list = new ArrayList<String>(Arrays.asList(subjects));
arrayadapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, subject_list);
listview.setAdapter(arrayadapter);
listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
subject_list.remove(position);
arrayadapter.notifyDataSetChanged();
Toast.makeText(MainActivity.this, "Item Deleted", Toast.LENGTH_LONG).show();
return true;
}
});
}
}
Here I had program of deleting item from list view by long click, instead of deleting item have to disable item by long clicking on the item in the ListView
.
2
Answers
Try This :
🙂 🙂
Try code like below
Happy Coding 🙂