标签: autocompletetextview

Android ArrayAdapter NullPointer

我正在尝试创建一个应用程序,它将使用AutoCompleteTextView并根据您键入的内容从您的联系人中读取,因此它不必处理大型数组.不幸的是,ArrayAdapter似乎并不喜欢我.这是我的代码:

    private void updateAdapter(String[] nC)
{

    autoAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_dropdown_item_1line, nC);

    autoText.setAdapter(autoAdapter);
}
Run Code Online (Sandbox Code Playgroud)

这引发了这个:

WARN/Filter(16767): An exception occured during performFiltering()!
java.lang.NullPointerException
04-21 11:23:48.819: WARN/Filter(16190):     
at android.widget.ArrayAdapter$ArrayFilter.performFiltering(ArrayAdapter.java:437)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.Handler.dispatchMessage(Handler.java:99)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.Looper.loop(Looper.java:144)
04-21 11:23:48.819: WARN/Filter(16190):     
at android.os.HandlerThread.run(HandlerThread.java:60)
Run Code Online (Sandbox Code Playgroud)

我真的不知道这里发生了什么.nC变量保存要放入AutoComplete的联系人姓名,这不是问题所在.

android nullpointerexception contacts autocompletetextview

2
推荐指数
1
解决办法
3962
查看次数

如何使用java代码将completionThreshold设置为AutoCompleteTextView?

我有这个AutoCompleteTextView:

AutoCompleteTextView a = new AutoCompleteTextView(this);
Run Code Online (Sandbox Code Playgroud)

我需要将completionThreshold标志值设置为1,我想学习使用java代码.我搜索谷歌和stackoverflow,我没有找到方法.

我只需要这样做: android:completionThreshold="1"使用java代码.

如何才能做到这一点?

android autocompletetextview android-layout layoutparams android-view

2
推荐指数
1
解决办法
6812
查看次数

Android适配器是异步的吗?

我从谷歌看了这个例子,它是一个适配器AutoCompleteTextView,可以通过网络调用API来检索自动完成的建议.

它不使用AsynkTask或线程,但不提供StrictMode警告,并且在没有互联网连接时不会锁定UI,我想知道为什么.

ArrayAdapter本身异步?

android autocompletetextview android-adapter

2
推荐指数
1
解决办法
1547
查看次数

Android:使用自定义适配器设置AutoCompleteTextView

我试图将此适配器类与AutoCompleteTextView一起使用.这个适配器是我在ListView中使用的适配器.查看文档,该类需要扩展ListAdapter和Filterable.BaseAdapter似乎扩展了ListAdapter,我的类实现了Filterable.但是,当我尝试将其设置为我的ACTV适配器时,我收到以下错误,我似乎无法理解它;

Bound mismatch: The generic method setAdapter(T) of type AutoCompleteTextView is not applicable for the arguments (CustomCardListAdapter). The inferred type CustomCardListAdapter is not a valid substitute for the bounded parameter <T extends ListAdapter & Filterable>
Run Code Online (Sandbox Code Playgroud)

我真的不知道这里缺少什么.这是代码:

public class CustomCardListAdapter extends BaseAdapter {
    // Main data structure
    private ArrayList<NRCard> cards;
    private ArrayList<NRCard> cardsBackup = null;
    private Context ctx;
    private CustomCardListAdapterFilter adapterFilter;

public CustomCardListAdapter(ArrayList<NRCard> cards, Context ctx) {
    this.cards = cards;
    this.cardsBackup = cards;
    this.ctx = ctx;
}

@Override
public int getCount() …
Run Code Online (Sandbox Code Playgroud)

android listview adapter autocompletetextview baseadapter

2
推荐指数
1
解决办法
5083
查看次数

自动完成延迟

我必须为我的应用程序设置自动完成功能.

我已经理解了AutoCompleteTextView操作,但我想动态修改String[]android自动完成所使用的.

我想做的事:调用PHP页面,它将给我String[],我会在我的AutoCompleteTextView使用,但我想做的事情,只有当一个关键是最后一个后按下至少500毫秒.


编辑:

好的,我错了.我想如果有上次记者后,按在500毫秒NO KEY我的AsyncTask运行(你知道,避免通过调用在键入的每一个字符的请求多收我们的服务器.)


我想我会这样做:

zipBox.setAdapter(myAdapter); //zipBox is an AutoCompleteTextView
zipBox.addTextChangedListener(new TextWatcher(){

    @Override
    public void onTextChanged(CharSequence s,
             int start, int before, int count){

        d = new Date();
        GetAutocompletion ac = new GetAutocompletion();
        ac.execute(zipBox.getText().toString());
    }
    // Other methods to implement
});


private class GetAutocompletion extends AsyncTask<String, String, String>{

    @Override
    protected String doInBackground(String... params){

        //adapter.notifyDataSetChanged();

        try{
             wait(500);
        } catch(InterruptedException e){}

        Date d1 = new Date();

        if(d1.getTime() - d.getTime() > 500){
            String res = "";

            try{

                URLConnection …
Run Code Online (Sandbox Code Playgroud)

android delay autocompletetextview

2
推荐指数
2
解决办法
3452
查看次数

建议未在AutoCompleteTextView中显示

我的布局中有一个AutoCompleteTextView.当用户输入"@"字符时,我必须向他们显示一些建议.它通常是我从互联网上得到它的名字.

我得到了名字,我创建了一个ArrayAdapter,如下所示.

autoCtextView.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            // TODO Auto-generated method stub
            String lsatChar = s.toString().substring(s.length()-1,s.length()); 
            if(lsatChar.equals("@")) {
                ArrayAdapter<String> adapter = new ArrayAdapter<String>(DisplayQuestionDetails.this, 
                         android.R.layout.simple_list_item_1, namesLsist);
                autoCtextView.setAdapter(adapter);
            }


        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }
    });
Run Code Online (Sandbox Code Playgroud)

但这些建议没有显示出来.我做错了吗?请询问是否需要澄清问题

android autocompletetextview

2
推荐指数
1
解决办法
7473
查看次数

在Android中使用JSON的AutoCompleteTextView

我正在尝试将JSON数组提取到一个AutoCompleteTextView但是我在下拉列表中获取每个值两次.

JSON:

{"names":[{"id":"1","names":"jacob"},{"id":"2","names":"amy"},{"id":"3","names":"melissa"}],"success":1,"message":"Successfully found "} 
Run Code Online (Sandbox Code Playgroud)

类Ajax:

class Ajax5 extends AsyncTask<String, String, String> {// JSON STARTS HERE

    // new CreateNewProduct().execute();

    protected ArrayList<NameValuePair> parameters;
    JSONObject json;

    public Ajax5() {
        super();
        parameters = new ArrayList<NameValuePair>();

    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    protected String doInBackground(String... args) {

        JSONParser jParser = new JSONParser();
        json = jParser
                .makeHttpRequest(
                        "http:link.php",
                        "GET", this.parameters);

        try {
            Log.d("Create Response", "four"
                    + json.getJSONObject("1").toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    protected void …
Run Code Online (Sandbox Code Playgroud)

android json autocompletetextview

2
推荐指数
1
解决办法
1299
查看次数

使用arraylist &lt;string&gt;在android中为自动完成的textview设置适配器

在我的Android应用程序中,我有一个arraylist包含从服务器接收的服务器数据。我需要在arrayadapter中使用此arraylist,以便在自动完成的文本视图中使用它,以便在用户键入字符时显示建议。我看过许多教程,在arrayadapter中使用字符串数组并将其设置为自动完成textview。但是还没有找到任何使用arraylist的解决方案。请帮帮我..

编辑:

这是我使用的代码:

View rootView = inflater.inflate(R.layout.fragment_community, container, false);
    actv1=(AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView1);
    actv2=(AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView2);
    loc=new ArrayList<String>();
    SplashScreen ss = new SplashScreen();
    loc=ss.loc;


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,loc);
Run Code Online (Sandbox Code Playgroud)

添加loc向我显示logcat中的错误,如下所示:构造函数ArrayAdapter(CommunityFragment,int,ArrayList)未定义

arrays android arraylist autocompletetextview

2
推荐指数
1
解决办法
3520
查看次数

在AutoCompleteTextView中设置值

我有一个带有项目列表的AutoCompleteTextView,我需要选择其中一个...

我做的事情如下:

myAutoCompleteTextView.setListSelection( index);
Run Code Online (Sandbox Code Playgroud)

和...

myAutoCompleteTextView.setText( index);
Run Code Online (Sandbox Code Playgroud)

但是不行......我怎么能默认设置一个项目?

android autocompletetextview

2
推荐指数
2
解决办法
7281
查看次数

如何为自动完成文本视图适配器设置边距

我已经autocompletetextview在工具栏内设置了。当用户提供搜索查询时,我有一个适配器(添加了一些用于测试的虚拟数据),可以显示基于搜索查询的结果。

问题是适配器宽度设置为autocompletetextview宽度。但是在这里,我希望将适配器宽度设置为工具栏宽度,以及工具栏和适配器之间的边距。

这是我写的代码:

searchView = (AutoCompleteTextView) findViewById(R.id.searchView);
SearchAdapter searchAdapter = new SearchAdapter(NavigationDrawerActivity.this,searchResults,searchView);
        searchView.setAdapter(searchAdapter);
Run Code Online (Sandbox Code Playgroud)

这是我的适配器:

public class SearchAdapter extends ArrayAdapter<SearchResult> {

    private boolean mAnimate;
    private AutoCompleteTextView mSearch;
    public SearchAdapter(Context context, List<SearchResult> options, AutoCompleteTextView search) {
        super(context, 0, options);
        mSearch = search;
    }

    int count = 0;

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SearchResult option = getItem(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(
                    R.layout.search_option, parent, false);

         /*   if (true) {
                Animation anim …
Run Code Online (Sandbox Code Playgroud)

android autocompletetextview baseadapter

2
推荐指数
1
解决办法
1842
查看次数