自动完成文本视图还是搜索对话框?

发布于 2024-12-28 22:44:15 字数 299 浏览 1 评论 0原文

我需要做的只是可以单击关键字的建议并将用户带到界面(xml 布局)。例如下面的结果:存在、丰富、缺乏。我在 R.layout.abide 中创建了它们

虽然 AutoCompleteTextView 似乎不那么麻烦,但是可以完成吗?或者唯一的方法是通过 SearchDialog?我没有使用 SearchWidget 因为我正在执行 api 级别 8。

在此处输入图像描述

What i need to be done are just the suggestions of keywords can be clicked and bring user to the interfaces (xml layout). For example the result below abide, abound, absence. I created them in R.layout.abide

Though AutoCompleteTextView seem to be less hassle but can it be done ? Or the only way to do it is through SearchDialog? I am not using SearchWidget because i am doing api level 8.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹倦 2025-01-04 22:44:15

如果我没记错的话,您希望用户只需从“自动完成”中选择一个项目,一旦他选择了它,它就会带您进入另一个活动。如果是这种情况,那么您可以按如下方式实现。

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.autocomplete_item,options);
 // R.layout.autocomplete_item is custom spinner item xml file.you can use default spinner item also.
autoComplete.setAdapter(adapter); 
autoComplete.setThreshold(1);
autoComplete.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {

        Intent intent;
        int index=999;
        for(int i=0;i<options.length;i++)
        {
            if(options[i].equals(autoComplete.getText().toString().trim()))
            {
                index=i;
                break;
            }
        }
        switch(index)
        {
            case 0:
                intent=new Intent(ThisActivity.this,ActivityZero.class);
                startActivity(intent);
                break;
            case 1:
                intent=new Intent(ThisActivity.this,ActivityOne.class);
                startActivity(intent);   
                break; 
                ...         
        }
    }
});

或者,如果您想保持相同的活动,但想根据用户在自动完成中所做的选择更改其 xml,那么您可以 setContentView(your xml);在上述情况下进行各种选择。

If I am not wrong,you want user to just select an item from AutoComplete and once he selects it,it should bring you to another activity.if it is the case then you can achieve it as below.

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.autocomplete_item,options);
 // R.layout.autocomplete_item is custom spinner item xml file.you can use default spinner item also.
autoComplete.setAdapter(adapter); 
autoComplete.setThreshold(1);
autoComplete.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) {

        Intent intent;
        int index=999;
        for(int i=0;i<options.length;i++)
        {
            if(options[i].equals(autoComplete.getText().toString().trim()))
            {
                index=i;
                break;
            }
        }
        switch(index)
        {
            case 0:
                intent=new Intent(ThisActivity.this,ActivityZero.class);
                startActivity(intent);
                break;
            case 1:
                intent=new Intent(ThisActivity.this,ActivityOne.class);
                startActivity(intent);   
                break; 
                ...         
        }
    }
});

Or if you want to stay on the same activity but want to change its xml according to the selection user makes in AutoComplete then you can setContentView(your xml); in above cases for various selection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文