Android的微调错误 [英] Android Spinner Error
本文介绍了Android的微调错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我尽量把我的java codeA微调,但它显示了其他的if语句错误:
hello I try to put in my java Code a Spinner, but it shows in the else if statement error:
private EditText textName;
private EditText textContent;
private Spinner CategorySpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text);
configureButton1();
configureButton2();
textName = (EditText) findViewById(R.id.editTextName);
textContent = (EditText) findViewById(R.id.editContent);
CategorySpinner = (Spinner) findViewById(R.id.editCategorySpinner);
}
private void configureButton1() {
Button del = (Button)findViewById(R.id.btNewText);
del.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent myIntent = new Intent(v.getContext(), StartActivity.class);
v.getContext().startActivity(myIntent);
}
});
}
private void configureButton2() {
Button save = (Button) findViewById(R.id.btSave);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (textName.getText().length() == 0) {
textName.requestFocus();
return;
} else if (textContent.getText().length() == 0) {
textContent.requestFocus();
return;
} else if (CategorySpinner.**getText**().length() == 0) {
CategorySpinner.requestFocus();
return;
} else {
//next Step: get the mood
Intent myIntent = new Intent(v.getContext(), Activity2.class);
myIntent.putExtra("textName", textName.getText().toString());
myIntent.putExtra("textContent", textContent.getText().toString());
myIntent.putExtra("CategorySpinner", CategorySpinner.**getText()**.toString());
v.getContext().startActivity(myIntent);
}
}
}
});
}
它示出了在CategorySpinner.getText()中的错误。我希望你能帮助我。 从来就尝试了很多,但没有找到一个解决方案。
it shows in the CategorySpinner.getText() an error. I hope you can help me. I´ve tried a lot, but not found a solution.
推荐答案
现在我已经加入了数组适配器,但它再次显示了其他-if语句错误:
Now I have add the Array Adapter, but it shows again in the else-if statement error:
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.category_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
categorySpinner = (Spinner) findViewById(R.id.editCategorySpinner);
categorySpinner.setAdapter(adapter);
categorySpinner.setOnItemSelectedListener(this);
}
private void configureButton2() {
Button save = (Button) findViewById(R.id.btSave);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (textName.getText().length() == 0) {
textName.requestFocus();
return;
} else if (textContent.getText().length() == 0) {
textContent.requestFocus();
return;
} else if (categorySpinner.**getText**().length() == 0) {
CategorySpinner.requestFocus();
return;
} else {
//next Step: get the mood
Intent myIntent = new Intent(v.getContext(), Activity2.class);
myIntent.putExtra("textName", textName.getText().toString());
myIntent.putExtra("textContent", textContent.**getText**().toString());
myIntent.putExtra("CategorySpinner", CategorySpinner.**getText()**.toString());
v.getContext().startActivity(myIntent);
}
}
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos,long id) {
String selected = parent.getItemAtPosition(pos).toString();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
我希望你能帮助我。
I hope you can help me.
这篇关于Android的微调错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文