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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:31:58+00:00 2026-05-22T16:31:58+00:00

The problem is when the ListView loses focus, the selected item isn’t highlighted. I

  • 0

The problem is when the ListView loses focus, the selected item isn’t highlighted.

I use a custom ArrayAdapter which uses the following layout for items:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ListTextBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/Padding"
    android:textSize="@dimen/TextSize"
  />

The ListSelector is a simple Shape drawable.

Thank you

edit…

Here is the ArrayAdapter:

listWords = new ArrayList<String>();
arrayAdapter = new DictListAdapter(this, R.layout.listtext, listWords); 
list.setAdapter(arrayAdapter);

and the code for DictListAdapter:

public class DictListAdapter extends ArrayAdapter<String> {
    public DictListAdapter(Context context, int textViewResourceId,
            List<String> objects) {
        super(context, textViewResourceId, objects);
        this.context = (MainWindow) context;
        this.objects = objects;
        this.res = textViewResourceId;
    }

    Typeface font;

    private List<String>  objects;
    private final MainWindow   context;

    int res;
    int gravity=Gravity.LEFT;

    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public String getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        String obj = objects.get(position);

        TextView tv = new TextView(context, null, res);
        tv.setText(obj);
        tv.setTypeface(context.getFont());
        tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, 
context.getResources().getDimension(R.dimen.TextSize));
        tv.setGravity(gravity);

        return tv;
        }

    public void setGravity(int g){
        this.gravity=g;
    }
}
  • 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-22T16:31:59+00:00Added an answer on May 22, 2026 at 4:31 pm

    i guess you have created array adapter in the following manner. if i am correct use the following:

    static final String[] color = new String[]{"red","green","blue"};
    

    We need to use the setListAdapter(..) method of the ListActivity class to bid the two (data and view). Android provides many implementations of the ListAdapter. We will use the simple ArrayAdapter.

    What does the ArrayAdapter expect?

    It expects the context object, the row layout and the data in an array.

    So here it is:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, PENS));
        getListView().setTextFilterEnabled(true);       
      }
    

    use below code to show selected item

    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        Object o = this.getListAdapter().getItem(position);
        String pen = o.toString();
        Toast.makeText(this, "You have chosen the color: " + " " + color, Toast.LENGTH_LONG).show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with my Android listview. My list uses a custom arrayadapter,
I have a following problem. I have a ListView which returns data from SQL
I am trying to delete the selected item from a ListView and the Problem
I have a problem with listview which list item contain a checkbox. When i
I have the following problem. The background color in a ListView is set LightGreen
I am using Listview,the View selected is largeicon mode. The problem i am facing
Here is the problem: I have a ListView as following: <UserControl.Resources> <DataTemplate x:Key="FirstCell"> <StackPanel
Interesting problem I'm having with a ListView. It's using a standard ArrayAdapter, with a
I have a big problem: I have a listview and each item links to
I have a listview in which a user can browse for assemblies, the problem

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.