[英]Displaying the listview items options on clicking the Clickable list
我正在尝试显示一个Toast消息,供用户显示他选择的项目。 我已将该列表作为另一个类的意图传递,并在类中接收它,其代码如下:
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中,如何在“你选择了”后自定义,我可以把上面定义的arraylist项中的值?
public void onListItemClick(ListView parent, View view, int position, long id)
{
Toast.makeText(this, "You have selected"+position, Toast.LENGTH_LONG).show();
}
如果你有索引和arraylist,那么你可以通过索引引用集合中的字符串:
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成为一个字段,以便能够从另一个方法引用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.