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 6125265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:13:40+00:00 2026-05-23T16:13:40+00:00

I am new to android and although I got this working before on a

  • 0

I am new to android and although I got this working before on a simpler project, I can not for the life of me figure out what is going on.

Here is the code for my ListActivity class:

public class ResultsActivity extends ListActivity {
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        // Get rid of the default title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        Bundle extras = this.getIntent().getExtras();
        if (extras != null)
        {
            String[] results = extras.getStringArray("results_to_display");
            this.setListAdapter(new ArrayAdapter<String>(this, R.layout.result_list_item, results));

            ListView listView = this.getListView();
            listView.setTextFilterEnabled(true);
            Toast.makeText(getApplicationContext(), "hello there", Toast.LENGTH_LONG).show();

            listView.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                    Log.d(ACTIVITY_SERVICE, "here now");
                    Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
                }
            });
        }

        this.setContentView(R.layout.result_list);
    }
}

I am able to get the list to display the content that I want, however, when clicking on an item it looks like onItemClick does not get executed. I have put a breakpoint in there as well.

Here is my layout file (not sure if it makes a difference)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/contentContainer"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">
    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"/> 
</LinearLayout>

Any help would be appreciated!

  • 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-05-23T16:13:41+00:00Added an answer on May 23, 2026 at 4:13 pm

    In a ListActivity you can override onListItemClick:

    public class ResultsActivity extends ListActivity {
        protected void onListItemClick (ListView l, View v, int position, long id){
    
        }
    }
    

    EDIT

    I found the problem. You set the layout (with setContentView) at the end of onCreate. The ListView you are setting the OnItemClickListener on is not the ListView you are seeing.

    The ListActivity creates its own contentView if you do not set one yourself. So you added the OnClickListener on the “default” ListView and at the end of onCreate the default one was replaced with a new one because setContentView was called.

    Actually one can create a ListActivity without setting the contentView.

    To solve the problem move setContentView at the top of onCreate.

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

Sidebar

Related Questions

I know that eclipse can do this, can Intellij via the new Android support
I'm pretty new to Android dev and still working out a lot of things.
I'm trying to record audio this.recorder = new android.media.MediaRecorder(); this.recorder.setAudioSource(android.media.MediaRecorder.AudioSource.MIC); this.recorder.setOutputFormat(android.media.MediaRecorder.OutputFormat.DEFAULT); this.recorder.setAudioEncoder(android.media.MediaRecorder.AudioEncoder.DEFAULT); this.recorder.setOutputFile(pruebaAudioRecorder.mp4); **this.recorder.prepare();**
Firstly I am new to android and Java so this is a beginners question.
I'm new to Android development and I'm currently going through some tutorials. When I
When creating a new android project, the build target has two choices: Android 2.2,
I'm completely new to Android development, but I just got a HTC Hero and
I'm moving a project to the new Android Native Development Kit (i.e. JNI) and
New Android developer here - I'm hoping this is simple. I want to create
When I start a new Android project in Eclipse (Helios), the strings.xml has 2

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.