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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:52:05+00:00 2026-05-27T10:52:05+00:00

How to differentiate between different items in list view, using ListActivity(Android) . For example

  • 0

How to differentiate between different items in list view, using ListActivity(Android). For example I want to change the text color of different items based on some conditions.

Can any body please give me some sample code to do this?

  • 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-27T10:52:06+00:00Added an answer on May 27, 2026 at 10:52 am

    I used this code for ListView adaper:

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
    
            View rowView;
            EntSaleDocumentDetails entSaleDocumentDetails = getItem(position);
    
            if (convertView == null) {
                LayoutInflater inflator = (LayoutInflater) getContext()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                rowView = inflator.inflate(R.layout.myLayout,
                        null);
            } else {
                rowView = (View) convertView;
            }
    
    
            TextView myTv= (TextView) rowView
                    .findViewById(R.id.tvCode);
    
            myTv.setTextSize(16);
    
            //....
    
            // set selected item
            LinearLayout ActiveItem = (LinearLayout) rowView;
            if (position == selectedItem)
            {
                ActiveItem
                        .setBackgroundResource(R.drawable.background_dark_blue);
            }
            else
            {
                ActiveItem
                        .setBackgroundResource(R.drawable.border02);
            }
            //....
    }
    
    public void setSelectedItem(int position) {
            selectedItem = position;
        }
    

    your custom layout:

    <?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:layout_gravity="right"
        android:background="@drawable/border02"
        android:gravity="right"
        android:orientation="vertical" >
    
        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@color/back_color_selector03"
            android:gravity="right" >
    
            <TextView
                android:id="@+id/tvName"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:gravity="right"
                android:text="TextView" >
            </TextView>
    
            <TextView
                android:id="@+id/tvCode"
                android:layout_width="100dip"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="TextView" />
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/llProductDetails"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/back_color_selector_blue_simple" >
    
            <ImageButton
                android:id="@+id/btnProductDetails"
                android:layout_width="40dip"
                android:layout_height="40dip"
                android:src="@drawable/prd_details" />
    
            <TableLayout
                android:id="@+id/tblProductDetails"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="right" >
    
                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right" >
    
                    <TextView
                        android:id="@+id/tvQty"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="right"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvLblQty"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvStockQty"
                        android:layout_width="100dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvLblStockQty"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
                </TableRow>
    
                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="right" >
    
                    <TextView
                        android:id="@+id/tvMablagh"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:gravity="right"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvLblMablagh"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvFee"
                        android:layout_width="100dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
    
                    <TextView
                        android:id="@+id/tvLblFee"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:gravity="right"
                        android:paddingLeft="20dip"
                        android:text="TextView"
                        android:textColor="@color/darkText" />
                </TableRow>
            </TableLayout>
        </LinearLayout>
    
    </LinearLayout>
    

    and in activity:

    @Override
        protected void onListItemClick(ListView parent, View view, int position,
                long id) {
            super.onListItemClick(parent, view, position, id);
            adapter.setSelectedItem(position);
            myListView.invalidateViews();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Google analytics and wish to differentiate between two different cases on
How to differentiate between two items in the ListView Activity(Android)?? As i am creating
I am new to programming. Using C# & ASP.Net, how would I differentiate between
How do you differentiate between an algorithm and a method? Why dont we call
I'm looking to differentiate between Core Solo/Duo and Core 2 Duo processors for 64-bit
How can I differentiate between two local branches in git ? How can I
Is there any guidelines on how to differentiate between .nil? , .blank? and .empty?
In python, there is no way to differentiate between arguments, local variables, and global
When creating a libsvm training file, how do you differentiate between a nominal attribute
Is there any way to differentiate IE7 versus IE6 using PHP's get_browser() function?

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.