不要在项目点击时将文本值设置为AutoCompleteTextView
创始人
2025-01-11 05:00:00
0

在项目中,如果你不想在点击时将文本值设置为AutoCompleteTextView,你可以使用以下解决方法:

  1. 在AutoCompleteTextView设置OnItemClickListener,然后在点击事件中手动设置文本值。示例代码如下:
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);

autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView parent, View view, int position, long id) {
        String selectedText = (String) parent.getItemAtPosition(position);
        autoCompleteTextView.setText(selectedText);
    }
});
  1. 自定义一个AutoCompleteTextView的子类,重写performCompletion方法,在此方法中避免设置文本值。示例代码如下:
public class CustomAutoCompleteTextView extends AutoCompleteTextView {

    public CustomAutoCompleteTextView(Context context) {
        super(context);
    }

    public CustomAutoCompleteTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void performCompletion() {
        // 不做任何操作,避免设置文本值
    }
}

然后在XML布局文件中使用CustomAutoCompleteTextView代替AutoCompleteTextView。


这样,当你点击AutoCompleteTextView时,不会自动设置文本值。你可以根据需要选择其中一种解决方法。

相关内容

热门资讯

wepoke有挂!wepoke... wepoke有挂!wepoke软件透明挂多少钱,wpk俱乐部系统,科技教程(有挂总结);无聊就玩这款...
aapoker透明挂!德扑之星... 1、aapoker透明挂!德扑之星真的太假了,aapoker俱乐部后天可以操作,力荐教程(有挂总结)...
aapoker外挂!gg扑克发... aapoker外挂!gg扑克发牌是不是有机制,微扑克辅助器代码,高科技教程(有挂黑科技)1)aapo...
wpk外挂!智星德州菠萝app... wpk外挂!智星德州菠萝app下载,德州之星辅助可以用,力荐教程(有挂了解)是一款可以让一直输的玩家...
德扑之星猫腻!wepoke的机... 德扑之星猫腻!wepoke的机制,菠萝德州辅助神器,曝光教程(有挂教学)是一款可以让一直输的玩家,快...
aapoker外挂!poker... aapoker外挂!pokerist有挂吗,pokermaster是有外挂,细节揭秘(有挂详情)是一...
智星德州菠萝外挂!wepoke... 智星德州菠萝外挂!wepoke真的,wepoke软件下载,高科技教程(有挂教学)您好,智星德州菠萝外...
智星德州菠萝偷偷看牌功能!wp... 智星德州菠萝偷偷看牌功能!wpk德州辅助,wpk数据分析,高科技教程(有挂介绍)是一款可以让一直输的...
wepoke有挂!wpk辅助器... wepoke有挂!wpk辅助器是真的,wepoke ai代打辅助,黑科技教程(有挂教程)1、不需要A...
wepoke有挂!微扑克ai辅... wepoke有挂!微扑克ai辅助会封号吗,微扑克有辅助,插件教程(有挂辅助挂)1、许多玩家不知道微扑...