Java 用户输入导致窗体出现
当用户在微调器上选择“组合”时,我想让EditText对象出现,我该怎么做 以下是我一直在尝试的:Java 用户输入导致窗体出现,java,android,forms,input,Java,Android,Forms,Input,当用户在微调器上选择“组合”时,我想让EditText对象出现,我该怎么做 以下是我一直在尝试的: ground = (Spinner) findViewById(R.id.ground); ArrayAdapter<CharSequence> groundAdapter = ArrayAdapter.createFromResource( this, R.array.ground_array, android.R.layout.simple
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);
}
什么是听众 您不应该将
AdapterView.OnItemSelectedListener
与其onItemSelected
方法一起使用吗
此外,使用setVisibility(View.VISIBLE)
而不是0以提高可读性
编辑:
我不明白你在用你的代码做什么,你的GroundListener没有连接到任何东西,你的测试在监听器之外
尝试:
ground.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Combination"))
{
combo.setVisibility(View.VISIBLE);
}
}
public void onNothingSelected(AdapterView parent)
{
// Do nothing.
}
});
ground.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共位置(AdapterView父项、视图、整数位置、长id){
if(parent.getItemAtPosition(pos.toString().equalsIgnoreCase(“组合”))
{
combo.setVisibility(View.VISIBLE);
}
}
未选择公共无效(AdapterView父级)
{
//什么也不做。
}
});
检查这是否有效,然后在GroundListener中返回代码,看看是否有效。不过,您可能有一个问题,即GroundListener可能不知道什么是combo。但你会解决的
编辑:
语法更正'public类GroundListener实现OnItemSelectedListener{public void onItemSelected(AdapterView父对象,视图视图,int pos,长id){String selected=parent.getItemAtPosition(pos.toString();}public void onNothingSelected(AdapterView父对象){//什么都不做。}}'这就是GroundListener。对不起,我应该把这个问题包括在内。我现在还不知道该怎么办。谢谢我真的很感激
ground.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if(parent.getItemAtPosition(pos).toString().equalsIgnoreCase("Combination"))
{
combo.setVisibility(View.VISIBLE);
}
}
public void onNothingSelected(AdapterView parent)
{
// Do nothing.
}
});