Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7806491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:33:12+00:00 2026-06-02T02:33:12+00:00

I a problem with my OnItemClickListener. It may be useful to note that I

  • 0

I a problem with my OnItemClickListener.
It may be useful to note that I have written this following the guidelines supplied by the android developer website:
http://developer.android.com/resources/tutorials/views/hello-listview.html

When setting the listener:

lv.setOnItemClickListener(new OnItemClickListener() {

I have the following error shown for the new “OnItemClickListener”

“The type new AdapterView.OnItemClickListener(){} must implement the inherited abstract method AdapterView.OnItemClickListener.onItemClick(AdapterView, View, int, long)”

Ive tried what eclipse suggests and added the apparently unimplemented method but it just generates a method that is almost identical apart from the actual specifics in the parameters e.g where I have

"int position"

the auto generated code has

"int arg2"

and by having this method in place it makes my method redundant as it wont get called (I think…)

I have attempted to alter various parts of the code such as the contents of the parameters etc but I have had no luck.
So im basically looking for some help to solve this problem please, any advice/direction will be appreciated.
My full code is shown below:

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class View extends ListActivity{
static final String[] entriesArray = new String[]{
    "One", "Two", "Three", "GO"};


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<String>(this, R.layout.dbrowviewer, entriesArray));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //When clicked show toast
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();
        }

    });

}
}

And the layout just in case.. (R.layout.dbrowviewer)

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textSize="16sp" >
</TextView>

Also if anyone has a spare second to give advice..I have an error with “(TextView) view.getText()” in the toast which states that I cannot cast from View to TextView. Have had a quick look into it with no luck but Im currently trying to solve the first and more important problem!

Thanks in advance,

Josh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:33:14+00:00Added an answer on June 2, 2026 at 2:33 am

    First, this is the code I modified and it worked.

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    
        @Override
        public void onItemClick(AdapterView<?> parnet, android.view.View view,
                int position, long id) {
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
                    Toast.LENGTH_SHORT).show();
        }
    
    });
    

    The problem here is your “class” name, you’ve chosen “View” as your class name, which happens to be the same as android.view.View, so if you use View as the type of the second parameter of your listener, the compiler gets confused.

    My suggestion is that, you’d better choose another name for your activity class. I usually use the functionality of the activity plus a “Activity” postfix as activity class name, for example, if you want to display a list of users, you can choose UserListActivity, here I choose the “ListActivity” as the postfix to indicate that the activity actually derives from ListActivity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have a problem with this aplication. import java.util.ArrayList; import java.util.List; import android.app.Activity;
EDIT: This problem may be related to BaseAdapter causing ListView to go out of
I have this particular problem which follows me since couple days. I used the
I've seen a few examples on here to this problem, but none have solved
Since java does not support multiple inheritance I have a problem getting this to
Hello i have problem with my sms aplication. import java.util.ArrayList; import java.util.List; import android.app.Activity;
I have a problem to call a java class from OnItemClickListener widget.. private OnItemClickListener
I make a program in Eclipse to Android and I have a problem. I
I have a problem with my Android listview. My list uses a custom arrayadapter,
Problem: I have two spreadsheets that each serve different purposes but contain one particular

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.