[英]how to remove checked items/ specific items from an array list / listview
我有这段代码,我习惯于将数组列表传递给另一个页面,并将其显示为列表视图。 当列表出现时,我希望能够检查一个项目并在“单击按钮”处将其删除,这将修改阵列。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.oppout);
final ListView lv2 = (ListView) findViewById (R.id.custom_list_view);
lv2.setClickable(true);
lv2.setAdapter(new ArrayAdapter<String>(Oppout.this,
android.R.layout.simple_list_item_checked,
Entername.playerList));
lv2.setOnItemClickListener (
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView adapterView,
View view,int arg2, long arg3) {
int selectedPosition = adapterView.getSelectedItemPosition();
Toast.makeText(getBaseContext(), "mu"+ selectedPosition,
Toast.LENGTH_SHORT).show();
}
});
Button next = (Button) findViewById(R.id.button1);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// on click call the adapterview and delete string at selected position.
// This is my problem, am not getting how to call the adapter and deleted
// the selected item/position
int selectedPosition = adapterView.getSelectedItemPosition();
adapterView.remove(player.SelectedPosition);
Intent myIntent = new Intent (view.getContext(), Callacab.class);
startActivityForResult(myIntent, 0);
}
});
}}
contact.remove(index); //将数组列表提供给适配器
arrayadapter.remove(index); //这是您将其提供给listview的适配器arrayadapter.notifyDataSetChanged();
//您可以从阵列列表或适配器中删除,然后notifyDataSetChanged(); 使效果在您的listview中发生....最好从arraylist中删除,它的索引将是listview项目侦听器中的arg2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.