自动完成onItemClickListener事件不会触发?

时间:2016-05-16 11:45:50

标签: android

我正在使用自动填充功能从Google API中获取地点。它的工作正常。它提取所有的地方下拉但事情是,如果我点击该项目,onItemClick监听器不适用于自动完成。

这是代码

// jQuery Framework in noConflict mode  
JHtml::_('jquery.framework', false);  

$document = JFactory::getDocument();  
$js =<<<JS
jQuery(document).ready(function(){  
    jQuery("#profiletypes").change(function(){  
        if(jQuery(this).attr("value")=="3"){  
            jQuery(".box").hide();  
            jQuery(".choose").show();  
        }  

        if(jQuery(this).attr("value")=="5"){  
            jQuery(".box").hide();  
            jQuery(".green").show();  
        }  

        if(jQuery(this).attr("value")=="6"){  
            jQuery(".box").hide();  
            jQuery(".blue").show();  
        }  

        if(jQuery(this).attr("value")=="7"){  
            jQuery(".box").hide();  
            jQuery(".red").show();  
        }  
    }).change();  
});
JS;
// The above 'JS' must be at the start of the line, not tabbed in

// Add the JS
$document->addScriptDeclaration($js);

此代码是PlacesAdapter的构造函数

   ArrayList<String> values=new ArrayList<String>();
            for(int i=0;i<result.size();i++)
            {
                values.add(result.get(i).get("description"));
            }


            PlacesAdapter placesAdapter=new PlacesAdapter(getActivity(),values);
            // Setting the adapter
            tempAutoCompleteTextView.setDropDownVerticalOffset(20);
            tempAutoCompleteTextView.setAdapter(placesAdapter);
            tempAutoCompleteTextView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Toast.makeText(getActivity(), "place"+postion, Toast.LENGTH_SHORT).show();
                    tempAutoCompleteTextView.setText(result.get(position).get("description"));
                }
            });

1 个答案:

答案 0 :(得分:1)

为了达到这个目的,你必须使用itemSelectedListener

  tempAutoCompleteTextView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {


            }
        });
相关问题