onItemClickListener has following arguments onItemClick(AdapterView arg0, View arg1,int arg2, long arg3) I am getting correct result from arg2 i.e. number of item which is selected but when i try to access string value from view program is crashing

    public void onItemClick(AdapterView<?> arg0, View arg1,int arg2, long arg3) 
        {
            String s = ((TextView)arg1).getText().toString();
            try
            {
                Log.v("----","ActionListener called"+arg2);
            }
            catch(Exception E)
            {
                Log.v("----","unable to get Text from Text field "+arg2);
            }
        }

when I comment Statement String S... code does not crash

有帮助吗?

解决方案

Problem is not in this code, i had similar problem and actually problem was in the definition of adapter try changing definition of adapter and it will work

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_single_choice, android.R.id.text1, Values);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top