gpt4 book ai didi

java - 当用户退出微调器时调用哪个事件

转载 作者:行者123 更新时间:2023-11-30 10:34:33 25 4
gpt4 key购买 nike

我有一个微调器,我想在用户退出微调器而不做任何事情时显示/隐藏一些东西。例如,当用户触摸微调器之外的区域时。附:容器布局的 onTouchEvent(在我的例子中是 LinearLayout)也没有被调用。这是我对自定义 spineer 的实现:

public SpinnerHintAdapter(Activity context, int resourceId, int textViewId, List<SpinnerItem> list, Spinner parent){

super(context,resourceId,textViewId, list);
flater = context.getLayoutInflater();
this.items = list;
this.gender = parent;

}

@Override
public int getCount() {
return items.size();
}

@Nullable
@Override
public SpinnerItem getItem(int position) {
return items.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
SpinnerItem spinnerItem = getItem(position);
View rowView = flater.inflate(R.layout.gender_item ,null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.main_text);
txtTitle.setText(spinnerItem.getName());
txtTitle.setTextColor(txtTitle.getResources().getColor(R.color.color_white));
Log.i(Tags.byEmail, "VVVVVVVVVVVVv");;
gender.setVisibility(View.VISIBLE);
return rowView;
}


@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
firstTime = false;
SpinnerItem rowItem = getItem(position);
View rowView = flater.inflate(R.layout.gender_drop_down_item ,null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.drop_down_text);
txtTitle.setText(rowItem.getName());
if(!isEnabled(position)){
txtTitle.setBackground(txtTitle.getResources().getDrawable(R.drawable.normal_rounded_text_field));
txtTitle.setTextColor(Color.parseColor("#777777"));
}
parent.setBackground(parent.getResources().getDrawable(R.drawable.normal_rounded_text_field));
txtTitle.setEnabled(isEnabled(position));
gender.setVisibility(View.INVISIBLE);
Log.i(Tags.byEmail, "DDDDDDDDDDDDDDDDDD");
return rowView;
}

@Override
public boolean isEnabled(int position) {
if(position == 0)
return false;
return super.isEnabled(position);
}

当用户在没有选择项目的情况下退出时,不会调用 getView 函数,因此性别(微调器对象本身)将不可见。我试过 OnItemSelected 和 OnNothingSelected 也没有被调用。事件 OnTouch 事件不会被调用。

用户退出时不会调用以下事件:1- OnItemSelected2- OnNothingSelected3- OnFocusChanged。4- 触摸

最佳答案

我认为这个事件对你来说就像魔法一样有效,不是吗?

public class CustomSpinner extends Spinner {

... Constructors ...

@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
Log.d(CustomSpinner.class.getSimpleName(), "onWindowFocusChanged: " + hasWindowFocus);
if (hasWindowFocus) {
// User click out of window
} else {
// User click in spinner window
}
}
}

关于java - 当用户退出微调器时调用哪个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41615987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com