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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:13:35+00:00 2026-05-20T11:13:35+00:00

I want to have a list of elements (using a ListView) and each element

  • 0

I want to have a list of elements (using a ListView) and each element in list is styled with a relative layout. Currently, the items are being displayed correctly, however, for some reason the listview items dont glow green when they’re clicked. Why is this?

I have removed all code to minimals and it still does this.

Activity class

package com.test;

import android.app.Activity;

public class My_ListView extends Activity
{
    private ListView_Adapter listViewAdapter;
    private ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_listview);


        // initialise the list-view object
        listViewAdapter = new ListView_Adapter(this);
        listView = (ListView) findViewById(R.id.listview);
        listView.setAdapter(listViewAdapter);


        for (int i=0;i<20;i++)
        {
            listViewAdapter.add("item "+i);
        }

    }
    public void clicked(View v)
    {
        v.setBackgroundColor(0xFF0000FF);
    }
}

The listview item adapter class

package com.test;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListView_Adapter extends ArrayAdapter<String>
{
    public ListView_Adapter(Context c)
    {
        super(c, R.layout.my_listview_item);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row = convertView;
        StationFinder_ListViewItemHolder holder = null;

        if (row == null)
        {
            LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            row = inflater.inflate(R.layout.my_listview_item, parent, false);
            holder = new StationFinder_ListViewItemHolder(row);
            row.setTag(holder);
        }
        else
        {
            holder = (StationFinder_ListViewItemHolder) row.getTag();
        }

        holder.populateFrom(getItem(position));

        return row;
    }

    static class StationFinder_ListViewItemHolder
    {
        private TextView destination = null;

        StationFinder_ListViewItemHolder(View row)
        {
            destination = (TextView) row.findViewById(R.id.text1);
        }

        void populateFrom(String locationDistance)
        {
            destination.setText(locationDistance);
        }

    }
}

my_listview.xml

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

    <ListView android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
</LinearLayout>

my_listview_item.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="wrap_content"
    android:onClick="clicked"
    >
    <TextView android:id="@+id/text1"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        />
</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-05-20T11:13:36+00:00Added an answer on May 20, 2026 at 11:13 am

    I think you may have to call invalidate() after setting the background color.

    You may want to do this instead by setting the listSelector and possibly drawSelectorOnTop for your ListView. That way the selection/deselection and clicks will be handled in the normal manner.

    Edit – also, since you’re using a ListView, you probably want to listen for clicks by setting an OnItemClickListener on your ListView.

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

Sidebar

Related Questions

i have created list of elements. if one element is highlighted (using buttons 'prev'
I have a list of input elements and using one selector I want to
I have an unordered list with elements and I want to append an item
I have a list of structs and I want to change one element. For
I have a list of items that I want to be laid out horizontally.
I have a list of elements (e.g. numbers) and I want to retrieve a
I have a list of elements in Erlang, and I'm using lists:foreach to traverse
I have a list of elements (the X in the following examples) displayed either
I want to have two TextView elements appear side by side (in a list
I have a list that is being fed in to my page using an

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.