Toast not generating text from selected item from list

故事扮演 提交于 2019-12-02 03:38:23
HashMap<String, String> selectedValue = (HashMap<String, String>) (lv.getItemAtPosition(position));         
ArrayList<String> list = new ArrayList<String>(selectedValue.keySet());             
Toast.makeText(getApplicationContext(), selectedValue.get("txt"), Toast.LENGTH_LONG).show();

That hashmap has got keys which are present in that list. That list is actually the from array which you have given. Just give the corresponding key to display the corresponding text.

Its working. :)

I hope this way get selected item

      lv.setOnItemClickListener(new OnItemClickListener() {

                    public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                            long arg3) {
                        // TODO Auto-generated method stub
                     //  Toast.makeText(getApplicationContext(),"Position is: "+ position, Toast.LENGTH_LONG).show();
                       String selectedFromList = lv.getItemAtPosition(position).toString();
                        Toast.makeText(getApplicationContext(),selectedFromList , Toast.LENGTH_LONG).show();
                    }
            });

Try

String selectedValue = from[position];

You can take the adapter and take value from it.

public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) 
            String selectedValue =(String) (lv.getAdapter().getItem(position));
            Toast.makeText(getApplicationContext(),Toast.LENGTH_LONG).show();
        }

I am so confused on what you are doing, why don't you just do it like this:

String selectedValue = items[position];

instead of:

String selectedValue =(String) (lv.getItemAtPosition(position));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!