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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:57:59+00:00 2026-06-05T20:57:59+00:00

I’d like to create an application for tablets using 2 panels. The left one

  • 0

I’d like to create an application for tablets using 2 panels. The left one as a menu and the right one as a content presenter. In fact the behavior I expect is similar to the one in Gmail app.

enter image description here

I’m currently using 2 fragments. One is basically a ListView with room names plus some buttons. The other one (the content) includes some information about the selected room.

The room I select in the left panel should stay highlighted – like in the Gmail app. I was trying for many hours to achieve this effect using selectors, but failed.

Moreover I found 2 different opinions about this approach..

1) “Do not try to keep the focus or selection in touch mode”

2) “In general, use the pane on the right to present more information about the item you selected in the left pane. Make sure to keep the item in the left pane selected in order to establish the relationship between the panels.”

Can you tell me how to achieve this (just to keep the selected item distinguished from the rest)?
Maybe a ListView isn’t the best approach here?

UPDATE

Thanks to Christoph Eberhardt’s answer I created a sample project that works fine. It’s available on github.

  • 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-05T20:58:00+00:00Added an answer on June 5, 2026 at 8:58 pm

    Create an xml file in res/drawable/list_item_selector.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_selected="true" android:drawable="@drawable/list_pressed" />
        <item android:drawable="@drawable/list_default" />
    </selector>
    

    For the list elements make an own xml file res/layout/list_item.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical"
        android:minHeight="?android:attr/listPreferredItemHeight"
        android:paddingLeft="20dp"
        android:background="@drawable/list_item_selector"
    />
    

    Then when creating the list adapter do:

    setListAdapter(new CustomAdapter<String>(getActivity(),
                R.layout.list_item, stringArray));
    

    Now all you have to do is providing the drawables list_default and list_pressed and list_altered

    The CustomAdpater looks like:

    package com.test.listview_keep_selected;
    
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.drawable.StateListDrawable;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    
    public class CustomAdapter<T> extends ArrayAdapter<T> {
    
        private Context m_cContext;
    
        public CustomAdapter(Context context, int textViewResourceId,
                T[] objects) {
    
            super(context, textViewResourceId, objects);
            this.m_cContext = context;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final View returnView = super.getView(position, convertView, parent);
            final ListView listView  = (ListView) ((Activity) m_cContext).findViewById(R.id.listViewTest);
            returnView.setOnClickListener(new OnClickListener(
                    ) {
    
    
                @Override
                public void onClick(View v) {
                    for(int i = 0; i< listView.getChildCount(); i++)
                        listView.getChildAt(i).setSelected(false);
                    StateListDrawable states = new StateListDrawable();
                    states.addState(new int[] {android.R.attr.state_selected},
                            m_cContext.getResources().getDrawable(R.drawable.list_pressed));
                    states.addState(new int[] { },
                            m_cContext.getResources().getDrawable(R.drawable.list_altered));
                    v.setBackgroundDrawable(states);
                    v.setSelected(true);
                }
            });
            return returnView;
        }
    
    }
    

    Edit:

    And if you don’t have it already:

    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    Edit:
    Don’t set the choice mode with a plain ListView, only makes sense if you have e.g. a ListFragment as I have in my code

    It’s not perfect now, but from now on you should be fine after playing around a bit.

    What also might help is: ListView item background via custom selector

    Edit:

    Now it should work as you want it^^

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

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.