OnItemClickListener

我有一个错误,说:“OnItemClickListener无法parsing为types”,当我在下面input代码:

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(new OnItemClickListener(){”。我不知道我做错了什么。

Solutions Collecting From Web of "OnItemClickListener"

我想通了,我input了错误的东西!

 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; 

这应该是这样的。

我有一个错误,说:“types视图中的方法setOnTouchListener(View.OnTouchListener)不适用于参数(new 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); } });