我想将android spinner选中的值存储到parse.com,在那里我创建了另一个列名作为分支。因此,每当任何用户注册并从下拉菜单中选择任何项目时,它将作为修复字符串存储到分支列名称中。 这是我的注册活动代码。
package com.goyllo.gecrajkot;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.internal.widget.AdapterViewCompat;
import android.view.View;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
public class SignUp extends ActionBarActivity implements AdapterView.OnItemSelectedListener {
protected EditText mUsername;
protected EditText mPassword;
protected EditText mEmail;
protected Button mSignUpButton;
protected Spinner mSpinnerBranch;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
mUsername = (EditText)findViewById(R.id.UsernameField);
mPassword =(EditText)findViewById(R.id.PasswordField);
mEmail =(EditText)findViewById(R.id.EmailField);
mSpinnerBranch = (Spinner)findViewById(R.id.spinner_branch);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.branch_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpinnerBranch.setAdapter(adapter);
mSignUpButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = mUsername.getText().toString();
String password = mPassword.getText().toString();
String email = mEmail.getText().toString();
username = username.trim();
password = password.trim();
email = email.trim();
if(username.isEmpty() || password.isEmpty() || email.isEmpty()){
AlertDialog.Builder builder = new AlertDialog.Builder(SignUp.this);
builder.setMessage(R.string.signup_error_message)
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
else{
// create the new user
setProgressBarIndeterminateVisibility(true);
ParseUser newUser = new ParseUser();
newUser.setUsername(username);
newUser.setPassword(password);
newUser.setEmail(email);
newUser.put("branch", SelectedBranch);
newUser.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
//success!
Intent intent = new Intent(SignUp.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(SignUp.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.signup_error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
// An item was selected. You can retrieve the selected item using
String SelectedBranch = parent.getItemAtPosition(pos).toString();
}
public void onNothingSelected(AdapterView<?> parent) {
// Another interface callback
}
});
}
我的下线代码有问题。不知道我做错了什么。或者如果您有任何其他建议,请在此处描述。
newUser.put(&#34; branch&#34;,SelectedBranch);