2
我有這樣的代碼我習慣一個數組列表傳遞到另一個頁面,並顯示它作爲一個列表視圖。當列表出現時,我希望能夠檢查一個項目,並在「按鈕點擊」將其修改數組中刪除它。如何刪除選中的項目/特定項目從一個數組列表/列表視圖
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);
}
});
}}
@Aleks G中ARG2,什麼也û編輯? – user1179083 2012-03-04 18:22:35
我更新了最後一種方法的格式和縮進。 – 2012-03-04 18:24:35
點擊標籤按鈕下面的「編輯」鏈接,你會看到差異。 – 2012-03-06 07:27:37