autocompletetextview setonitemselectedlistener not working

前端 未结 3 1511
生来不讨喜
生来不讨喜 2021-02-06 23:25

there i am trying to write code for authorisation activity. When i am putting some entry in inputEmail i expect that my inputPasword will be fileed automaticly if corresponding

相关标签:
3条回答
  • 2021-02-06 23:33

    Use setOnItemClickListener and don't use setOnItemSelectedListener. Also use your custom adapter object to fetch the selected values.

     prodNameAutoCompTxt.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    
    
                    @Override
                    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                        //Don't use this method
                    }
    
                    @Override
                    public void onNothingSelected(AdapterView<?> adapterView) {
                        System.out.println("Nothing selected");
                    }
                });
                prodNameAutoCompTxt.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                        //Use this method
                        Product prodObj=(Product) prodAutoAdapter.getItem(i);
                        new UomSynch().execute(prodObj.getProdID());
                    }
                });
    
    0 讨论(0)
  • 2021-02-06 23:44

    This is a duplicate of this question

    However, you need to use AdapterView.OnItemClickListener() not OnItemSelectedListener.

    I tested it with success using the following code snippet. Credit to Vogella for the adapter stuff.

        AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autocomplete_textview);
    
        String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                "Linux", "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux",
                "OS/2", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2",
                "Android", "iPhone", "WindowsMobile" };
    
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < values.length; ++i) {
            list.add(values[i]);
        }
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, list);
        actv.setAdapter(adapter);
    
        actv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                Toast.makeText(MainActivity.this,
                        adapter.getItem(position).toString(),
                        Toast.LENGTH_SHORT).show();
            }
        });
    
    0 讨论(0)
  • 2021-02-06 23:50
    autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String selectedItem=autoCompleteTextView.getAdapter().getItem(position).toString();
                Toast.makeText(getApplicationContext(),selectedItem ,  Toast.LENGTH_SHORT).show();
            }
        });
    

    Just get the adapter of AutoCompleteTextView and use the position.

    0 讨论(0)
提交回复
热议问题