我正在尝试隐藏或显示编辑文本,从我的应用程序中的微调器中选择项目。这是代码,请建议如何解决它
ArrayAdapter adapter1 = ArrayAdapter.createFromResource(
this, R.array.country_array, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
rlDate.setVisibility(View.VISIBLE);
rlTime.setVisibility(View.VISIBLE);
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
答案 0 :(得分:2)
rlDate.setVisibility(View.GONE);
会使视图'消失'。
答案 1 :(得分:1)
希望你的微调器和它的点击事件很好。然后你可以添加下面的代码来禁用或编辑edittext:
int count = 0;
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
**if(count == 0){
rlDate.setVisibility(View.VISIBLE);
count == 1;
}else{
rlDate.setVisibility(View.INVISIBLE);
count = 0;
}**
}
});
每次点击spinner时都会设置edittext的可见性。希望这可行..
答案 2 :(得分:0)
这就是我实现我的想法:
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (Objects.equals(spinner1.getSelectedItem().toString(), "<item_text_value>")) {
rlDate.setVisibility(View.VISIBLE);
rlTime.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
rlDate.setVisibility(View.GONE);
rlTime.setVisibility(View.GONE);
}
});
希望这有助于你 - 如果你仍然遇到这个问题 - 或者其他任何人正在使用它。
干杯!
答案 3 :(得分:-1)
下面是hode Edittext的代码
EditText.setVisibility(View.GONE);
答案 4 :(得分:-1)
EditText ta=(EditText)findviewById(R.id.***);
ta.setVisibility(View.GONE);