我有一个名为BuyCoins的类,在这个类中我有一个方法addListenerOnSpinnerItemSelection()
Sub consolidate(z)
Sheets(z).Range("B1:AXH100").Delete '''deletes former values'''
For i = 1 To 30
For x = 1 To 500
If IsEmpty(Sheets("Sheet1").Cells(x, 13)) Then 'if cell value is empty skip it'
a = 1
Else:
If Sheets("Sheet1").Cells(x, 18) = Sheets(z).Cells(1, 1) Then 'check to see if value is same'
If Sheets("Sheet1").Cells(x, 13) = Sheets(z).Cells(i, 1) Then 'check to see if value is same'
Sheets("Sheet1").Cells(x, 15).Copy 'copy value'
Sheets(z).Select 'select second sheet'
Cells(i, 1).Select
ActiveSheet.Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Offset(0, 1).Select 'offsets cell to the
left'
Selection.PasteSpecial past:=xlPasteValues 'pastes'
End Sub
这会创建一个新对象,用于检测在微调器上选择的项目(产品)。 我想把它传回BuyClass。我试图用注释掉的行来做这个,但是我收到的值是null。
series: [{
name: 'companyA',
data: results[0]
}, {
name: 'companyB',
data: results[1]
}]
答案 0 :(得分:0)
问题是你在添加后立即查询监听器,即事件不可能发生。由于你不知道 偶然发生了什么(如果有的话),你需要将它解耦。
示例(简单的伪代码,只是为了让您入门):
class Model {
String stock;
}
class Listener {
Model model;
Listener( Model m) {
model = m;
}
//In your case Component might be the spinner or its parent, depending on the rest of your code
void onItemSelected( Component c ) {
m.stock = c.getText();
}
}
当您创建并注册监听器时:
class BuyCoins {
Model model; //initialize
...
void initListeners() {
spinner.addListener( new Listener(model) );
}
}
答案 1 :(得分:0)
感谢大家,设法通过在后续活动中添加以下内容来解决问题。
public void onBuyCoinButtonClicked(View arg0) {
spinner1 = (Spinner) findViewById(R.id.spinner1);
String product= spinner1.getSelectedItem().toString();
Toast.makeText(this,
"product : " + product,
Toast.LENGTH_SHORT).show();
简易解决方法