Reputation:
i have been trying to apply the Gridview Tutorial but i'm stuck in an error, i know it will be easy but i can not get it though, i'm still so beginner, anyway here is the error :
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(HelloGridView.this, "" + position, Toast.LENGTH_SHORT).show();
the ( setOnItemClickListener ) have a red line under it as well as ( OnItemClickListener ) and ( HelloGridView ) .... could anyone please which way i went wrong ... ?
note :
my project name is : GridView1
i'm using eclpise and android skd 15
i have already made the ( ImageAdapter.Java ) Class - Fine
i dunno what is wrong so far .... help
Upvotes: 0
Views: 1810
Reputation: 2091
If you are getting red line below setOnItemClickListener and OnItemClickListener that means you are not importing proper classes so try to first import all required classes (in eclipse that is ctrl+shift+o in eclipse(windows)).
But one thing that you are telling is that you also getting red line below HelloGridView ,however this should not happen(because this is class name and HelloGridView .this will be context(this is very basic but as you said you are new I am telling you)) kindly check your class whether it is extending to Activity or not like this
HelloGridView extends Activity
If you have done this thing also, kindly check for required jar files that your application needs, you can check this by right click your project Java Build Path ->Order and export select your api(contains jar file,if not selected) press select all button and press OK and you are done then.
If still you do not get classes that you required you clean your project that is Project -> clean
Upvotes: 1
Reputation: 11447
do as @jitendra says or alternatively do so:
gridview.setOnItemClickListener(new View.OnItemClickListener() {...}
Notice the use of View
to fully qualify the OnItemClickListener
.
Upvotes: 0
Reputation: 29199
You need to import OnItemClickListener
add following import statement
import android.widget.AdapterView.OnItemClickListener;
Upvotes: 0