android spinner问题,在其他类中如何获取spinner选中的值?附代码,每次运行到这里就卡死了~求大神~
publicvoidonClick(Viewv){//TODOAuto-generatedmethodstubresult.setText("");Stringbusli...
public void onClick(View v) {
// TODO Auto-generated method stub
result.setText(" ");
String busline = key.getText().toString();
Spinner spinner = null;
Bus bus = new Bus();
StringBuffer lines = new StringBuffer();
Cursor cursor = null;
if (busline != null && !busline.equals("")) {
System.out.println(spinner.getSelectedItem().toString());
if(spinner.getSelectedItem().toString().equals ("长沙"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='长沙' and line like '%"
+ busline + "%'", null);
if(spinner.getSelectedItem().toString().equals("深圳"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='深圳' and line like '%"
+ busline + "%'", null);
if(spinner.getSelectedItem().toString().equals("广州"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='广州' and line like '%"
+ busline + "%'", null); 展开
// TODO Auto-generated method stub
result.setText(" ");
String busline = key.getText().toString();
Spinner spinner = null;
Bus bus = new Bus();
StringBuffer lines = new StringBuffer();
Cursor cursor = null;
if (busline != null && !busline.equals("")) {
System.out.println(spinner.getSelectedItem().toString());
if(spinner.getSelectedItem().toString().equals ("长沙"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='长沙' and line like '%"
+ busline + "%'", null);
if(spinner.getSelectedItem().toString().equals("深圳"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='深圳' and line like '%"
+ busline + "%'", null);
if(spinner.getSelectedItem().toString().equals("广州"))
cursor = database.rawQuery(
"select id,line,time,station,opposite from bus_line where city='广州' and line like '%"
+ busline + "%'", null); 展开
展开全部
speed.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id) {
sendBroadcast(new Intent("ACTION").putExtra("position", position));//通过广布把选中的位置发过去,如果你要发送这个位置的数据,那么你可以通过position获取。
}
在接收的类,写个广播接收器就可以了。
public void onItemSelected(AdapterView<?> adapter, View view,
int position, long id) {
sendBroadcast(new Intent("ACTION").putExtra("position", position));//通过广布把选中的位置发过去,如果你要发送这个位置的数据,那么你可以通过position获取。
}
在接收的类,写个广播接收器就可以了。
更多追问追答
追问
如果我使用intent+bundle来实现spinner选中值的传递的话,要怎么实现呢?
追答
都说了发广播了,试试不就知道行不行了?反正我是这样做的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询