2

I am working my way through some of the android developers tutorial, specifically the Gallery View Widget located here I have made it through stages 1 and 2 yet I seem to be getting 3 errors and I cannot fathom what it is I have done wrong, as I have copied and pasted the code direct from the tutorial and made one change to the code, that being R.layout.events instead of R.layout.main

Here is the code

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Gallery;
import android.widget.Toast;
public class Events extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.events);
 Gallery gallery = (Gallery) findViewById(R.id.gallery1);
 gallery.setAdapter(new ImageAdapter (this));
 gallery.setOnClickListener(new OnItemClickListener() {
 public void onItemClick(AdapterView parent, View v, int position, long id) {
 Toast.makeText(Events.this, "" + position, Toast.LENGTH_LONG).show();
 }
 });
}}

The errors that I am getting are as follows:

ImageAdapter cannot be resolved to a type line 18 Java Problem OnItemClickListener cannot be resolved to a type line 20 Java Problem

The method setOnClickListener(View.OnClickListener) in the type AdapterView is not applicable for the arguments (new OnItemClickListener(){}) line 20 Java Problem

Any advice or pointers would be greatly appreciated. Thanks in Advance.

asked Jan 24, 2012 at 20:19
2
  • We can't actually see what errors you're getting. Seems like it would be easier to help if we could. Commented Jan 24, 2012 at 20:21
  • Sorry, I realized this post, posting and was adding them in whilst you was commenting. Commented Jan 24, 2012 at 20:23

2 Answers 2

6

The ImageAdapter is a custom BaseAdapter defined further in the post, at point 6.

A custom BaseAdapter called ImageAdapter is instantiated (...)

And at point 6:

public class ImageAdapter extends BaseAdapter { //(...)
answered Jan 24, 2012 at 20:29
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks alot, I feel kinda dumb for not going all the way through now
3

Wrong listener type. It should be View.OnClickListener.

gallery.setOnClickListener(new View.OnClickListener() { ....

Or use setOnItemClickListener...

gallery.setOnItemClickListener(new AdapterView.OnItemClickListener() { ...
answered Jan 24, 2012 at 20:29

1 Comment

Thank you as well, that also fixed those specific errors. Is it standard for Android Dev to have errors in their tutorials?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.