我很难将我的微调器的值发送到我的Web服务器。我的表单上有一些文本区域和一个微调器。我可以获取textareas的值,将其发布到我的服务器并将它们保存到数据库中。但我似乎无法找到一种方法来与纺纱厂一起做这件事。
有人可以帮忙吗?
MainActivity.java:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.planets_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
etPostCode = (EditText) findViewById(R.id.etPostCode);
etAddress1 = (EditText) findViewById(R.id.etAddress1);
etRecordNum = (EditText) findViewById(R.id.etRecordNum);
etContainerType = (EditText) findViewById(R.id.etContainerType);
etContainerSize = (EditText) findViewById(R.id.etContainerSize);
etContainerSerial = (EditText) findViewById(R.id.etContainerSerial);
}
public void signup(View v) {
String postCode = etPostCode.getText().toString();
String address1 = etAddress1.getText().toString();
String recordNum = etRecordNum.getText().toString();
String containerType = etContainerType.getText().toString();
String containerSize = etContainerSize.getText().toString();
String containerSerial = etContainerSerial.getText().toString();
Toast.makeText(this, "Adding Record...", Toast.LENGTH_SHORT).show();
new SignupActivity(this).execute(postCode, address1, recordNum, containerType, containerSize, containerSerial);
}
我的Spinner在conent_main.xml中:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_marginTop="30dp"
android:layout_gravity="center_horizontal" />
我试过使用String spinner = Spinner.getSelectedItem()。toSting();
但我收到错误:
非静态方法&#39; getSelectedItem()&#39;无法从静态上下文引用
答案 0 :(得分:2)
尝试在您的微调器中添加侦听器:
AdapterView.OnItemSelectedListener mSelectedItemListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String spinner = mSpinner.getSelectedItem().toString();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {}
};
并在你的微调器上设置监听器:
mSpinner.setOnItemSelectedListener(mSelectedItemListener);