开发者

OnItemClickListener

开发者 https://www.devze.com 2023-01-20 08:59 出处:网络
I have an error that says \"OnItemClickListener cannot be resolved to a type\" when I enter this code in:

I have an error that says "OnItemClickListener cannot be resolved to a type" when I enter this code in:

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.makeTex开发者_StackOverflow中文版t(getApplicationContext(), ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();
      }
    });

 }
}

It occurs right at the "lv.setOnItemClickListener(new OnItemClickListener() {". I'm not sure what I'm doing wrong.


I figured it out, I had imported the wrong items!

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;

That is what it should look like.


I have an error that says"The method setOnTouchListener(View.OnTouchListener) in the type View is not applicable for the arguments (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);
        }

    });
0

精彩评论

暂无评论...
验证码 换一张
取 消