• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problem with Inner Classes

andravis

Lurker
hey everyone,

i'm pretty new to programming for android, i'm using eclipse as my ide, and i'm having difficulty with anonymous inner classes. for instance, i'll simply copy/paste example code from android.com or write my own code and everything goes fine until i reach an anonymous class.

for example, i've copied/pasted the following from android.com:

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();
}
});

and the error occurs with OnItemClickListener() { ... on the first line. the problem description in eclipse reads, "OnItemClickListener cannot be resolved to a type."

any suggestions?

thanks everyone,

andrew
 
The problem isn't with the inner class per-se; the problem is that Java can't find OnItemClickListener. Make sure you either import it at the top of the file with "import android.widget.AdapterView.OnItemClickListener;" or define your inner class as "...new android.widget.AdapterView.OnItemClickListener()..."
 
Hi I'm trying some of the Android applications for practice purpose, but i'm facing a lof of problems while development, the most common problem is- id/main cannot b resolve to the type, can i get a proper suggestion for my query. Also m working on Linux n while runnig my application i see that it takes purely 5mins for a emulator to show the output, so i just wanted to know that is it usual with Linux???
 
Back
Top Bottom