点击类别,并通过Toast将类别的名字显示出来

点击类别时不能显示出来,发现有异常却并不报错

listView.setOnItemClickListener(new OnItemClickListener(){
    	 public void onItemClick(AdapterViewav, View v, int
    			 position, long id) {
..........
显示的异常是:

The method setOnItemClickListener(AdapterView.OnItemClickListener) 
in the type AdapterView
 is not applicable for the arguments (new OnItemClickListener(){})
需要的是AdapterView.OnItemClickListener,鼠标放在OnItemClickListener上,
其实是另一种view的OnItemClickListener。
所以为了避免混淆就直接写new AdapterView.OnItemClickListener(){...},
并导入android.widget.AdapterView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
		{
		     public void onItemClick(AdapterViewadapterView, View viewc, int
	    			 position, long id) {
		     Category category = categoryList.get(position);  
             Toast.makeText(StudyActivity.this, category.getName(),  
                        Toast.LENGTH_LONG).show();  
  
            }
		
		});
好了!现在就可以正常显示了 点击类别,并通过Toast将类别的名字显示出来_第1张图片


你可能感兴趣的:(点击类别,并通过Toast将类别的名字显示出来)