2010-10-14 79 views
17

我,說:「OnItemClickListener不能被解析爲一個類型」當我輸入驗證碼錯誤:OnItemClickListener

package com.funkystudios.android.facts; 

import android.app.ListActivity; 
import android.os.Bundle; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 






public class activity2 extends ListActivity { 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    String[] Facts = getResources().getStringArray(R.array.Facts_Array); 
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list, Facts)); 
    ListView lv = getListView(); 
    lv.setTextFilterEnabled(true); 
    lv.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView<?> parent, View view, 
      int position, long id) { 
     // When clicked, show a toast with the TextView text 
     Toast.makeText(getApplicationContext(), ((TextView) view).getText(), 
      Toast.LENGTH_SHORT).show(); 
     } 
    }); 

} 
} 

它發生就在「lv.setOnItemClickListener(新OnItemClickListener(){」。我不知道我在做什麼錯。

+3

您還沒有進口OnItemClickListener錯誤 – kiki 2010-10-14 04:34:41

回答

22

我想通了,我已經進口了錯誤的物品!

import android.app.ListActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.AdapterView; 
import android.widget.ArrayAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 
import android.widget.AdapterView.OnItemClickListener; 

也就是說它應該是什麼樣子。

+1

這就是我喜歡的日食:) – schwiz 2010-10-14 02:14:54

+1

通常日食會在quickfix中列出這樣的東西,但我的版本不會在這種情況下... – Julian 2011-07-22 21:27:58

+1

同樣在這裏。有時它有幫助,有時它什麼都不做! – 2011-07-28 18:13:58

3

我,說:「在類型視圖的方法setOnTouchListener(View.OnTouchListener)不適用於參數(新CarouselAdapter.OnItemClickListener(){})」

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    Carousel carousel = (Carousel)findViewById(R.id.carousel); 
    carousel.setOnItemClickListener(new OnItemClickListener(){ 
     LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayout01); 
     LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, 
       LayoutParams.WRAP_CONTENT); 
     //String[]img = getResources().getStringArray(R.array.entries); 

     //img.setDrawingCacheEnabled(true); 
     //img.setOnTouchListener(this); 
     //@Override 
     public void onItemClick(CarouselAdapter<?> parent, View view, 
       int position, long id) {     
      Toast.makeText(MainActivity.this, "Position=" + position, Toast.LENGTH_SHORT).show();    
      view.setDrawingCacheEnabled(true); 
      view.setOnTouchListener(this); 
     } 

    });