我正在嘗試顯示一個用於顯示他已選擇的項的用戶的吐司消息。我已經在名單上走過了從一個另一個類的意圖,並在其代碼如下階級接受了它:在單擊可點擊列表時顯示列表視圖項選項
public class ListViewDelete extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_list_view_delete);
final Intent intent = getIntent();
final Bundle extras = getIntent().getExtras(); //gets the GWID
final MySQLitehelper dbhelper = new MySQLitehelper(this);
ArrayList<String> thelist = new ArrayList<String>(extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE));
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE)));
}
public void onListItemClick(ListView parent, View view, int position, long id)
{
Toast.makeText(this, "You have selected", Toast.LENGTH_LONG).show();
}
}
在過去onListItemClick,我該如何自定義了「您已選擇」後,我可以把上面定義的數組列表項的值?
public class ListViewDelete extends ListActivity {
private ArrayList<String> thelist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_list_view_delete);
final Intent intent = getIntent();
final Bundle extras = getIntent().getExtras(); //gets the GWID
final MySQLitehelper dbhelper = new MySQLitehelper(this);
thelist = new ArrayList<String>(extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE));
setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,extras.getStringArrayList(SelectOptions.EXTRA_MESSAGE)));
}
public void onListItemClick(ListView parent, View view, int position, long id)
{
Toast.makeText(this, "You have selected" + thelist.get(position), Toast.LENGTH_LONG).show();
}
}
請注意,我所做的ArrayList的一個字段,以便能夠:
工作奇蹟。謝啦。你搖滾。 – noobcoder