用户输入导致表单出现
我希望当用户在微调器上选择“组合”时显示 EditText 对象,我该怎么做?
这是我一直在尝试的:
ground = (Spinner) findViewById(R.id.ground);
ArrayAdapter<CharSequence> groundAdapter = ArrayAdapter.createFromResource(
this, R.array.ground_array, android.R.layout.simple_spinner_item);
groundAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ground.setAdapter(groundAdapter);
ground.setOnItemSelectedListener(new GroundListener());
if(ground.getSelectedItem().toString().equalsIgnoreCase("Combination"))
{
combo.setVisibility(0);
}
EditText 对象组合在 xml 文件中设置为 android:visibility="gone"
GroundListener 代码是
public class GroundListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String selected = parent.getItemAtPosition(pos).toString();
}
public void onNothingSelected(AdapterView parent)
{
// Do nothing.
}
}
I want to have EditText object appear when a the User chooses "Combination" on a Spinner, How would I do this?
Here is what I have been trying:
ground = (Spinner) findViewById(R.id.ground);
ArrayAdapter<CharSequence> groundAdapter = ArrayAdapter.createFromResource(
this, R.array.ground_array, android.R.layout.simple_spinner_item);
groundAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ground.setAdapter(groundAdapter);
ground.setOnItemSelectedListener(new GroundListener());
if(ground.getSelectedItem().toString().equalsIgnoreCase("Combination"))
{
combo.setVisibility(0);
}
the EditText object combo is set in xml file as android:visibility="gone"
GroundListener Code is
public class GroundListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String selected = parent.getItemAtPosition(pos).toString();
}
public void onNothingSelected(AdapterView parent)
{
// Do nothing.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
什么是地面监听器?
您不应该使用
AdapterView.OnItemSelectedListener
及其onItemSelected
方法吗?此外,为了便于阅读,请使用
setVisibility(View.VISIBLE)
而不是 0。编辑:
我不明白你在用你的代码做什么,你的 GroundListener 没有插入任何东西,你的测试在监听器之外。
尝试:
检查是否有效,然后返回 GroundListener 中的代码以查看是否有效。但您可能会遇到问题,因为 GroundListener 可能不知道什么是组合。但你会解决这个问题的。
编辑:
语法更正
What is a GroundListener ?
Shouldn't you be using an
AdapterView.OnItemSelectedListener
with itsonItemSelected
method ?Beside, use
setVisibility(View.VISIBLE)
instead of 0 for readability.EDIT:
I don't understand what you are doing with your code, your GroundListener is not plugged to anything and your test is outside of the listener.
Try :
Check if that works and then bring back the code in your GroundListener to see if it works. You might have a problem though with the fact that the GroundListener might not know what is combo. But you'll work that out.
Edit:
Syntax Correction