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

  • Home
  • SEARCH
  • 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 7879453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:54:07+00:00 2026-06-03T03:54:07+00:00

I am creating a listView in Android using the following code : ListView listView

  • 0

I am creating a listView in Android using the following code :

 ListView listView = (ListView) List.this.findViewById(R.id.mylist);
         listView.setTextFilterEnabled(true);

         String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" ,"asdsad","asdsdsa","asdasdsa"};

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.list_item,values);

            // Assign adapter to ListView

            listView.setAdapter(adapter);
            listView.setVisibility(0);

Now I want to Toast a selected Item from my ListView so I use the following code :

listView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {

                    String item = ((TextView)view).getText().toString();

                    Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show();

                }
            });

But Unfortunately I am getting error for the following piece of code

listView.setOnItemClickListener(new OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position,
                            long id)

The error is

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

So What Should I do to correct this error and also print my listview element?
Edited

Entire Code

package com.notification;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.view.*;

public class List1 extends Activity 
{

Context context=this;

@Override
        public void onCreate(Bundle savedInstanceState)
        {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        //ListView
        try{

         ListView listView = (ListView) List1.this.findViewById(R.id.mylist);
         listView.setTextFilterEnabled(true);

         String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
            "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
            "Linux", "OS/2" ,"asdsad","asdsdsa","asdasdsa"};

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.list_item,values);

            // Assign adapter to ListView

            listView.setAdapter(adapter);
            listView.setVisibility(0);

            //required
            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View view, int position,long id)
                //public void onItemClick(ListView<?> listview, View view, int position,long id)
                {

                 Toast.makeText(List1.this, "hi",Toast.LENGTH_LONG).show();
                }
            });


            //required
            }
       catch(Exception e)
       {
        Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_LONG).show();}
       }
}

Nothing is getting toasted. why?

Edit 2
list_item.xml

<?xml version="1.0" encoding="utf-8"?>



<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:id="@+id/tv1"
    android:padding="10dp"
    android:background="@drawable/textview1"
    style="@style/textview_text"
    android:textSize="16dp">


</Button>

listview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


  <ListView
        android:id="@+id/mylist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</RelativeLayout>
  • 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-03T03:54:08+00:00Added an answer on June 3, 2026 at 3:54 am

    You have set your java compiler version to 1.5 so its giving error.

    Two things you can do.

    1) remove @Override written before onItemClick

    2) right-click project - properties - java compiler - check-Enable project setting - change to 1.6

    Also there is other changes required.

    Use YouActivityName.this instead getBaseContext() while showing Toast

    Item can be null so change…String item = values[position]

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

Sidebar

Related Questions

Im populating a ListView using the following: list = (ListView) findViewById(R.id.historylist); ArrayList<HashMap<String, String>> mylist
Hi I am creating a List View in another List View using this code
I'm creating a list of pictures using a ListView and the photos are of
I am using the following code by the Android-people-XMLParsing example for parsing XML file
Is there any way creating a photo gallery using Listview control ? Im playing
When creating a website using Asp.Net and using controls such as the ListView is
I am using XML file for creating Context Menu for my ListView. (Please see
Creating a view with following code. - (void)loadView { paintView=[[UIView alloc]initWithFrame:CGRectMake(0, 50, 320, 430)];
I am creating a highscore list in my android app. I am returning the
When overriding the baseadapter on an android listview, you have to implement this method

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.