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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:19:03+00:00 2026-06-15T11:19:03+00:00

I have created a custom ArrayList which is working as it should barring an

  • 0

I have created a custom ArrayList which is working as it should barring an issue with the onClick. I orginally had the ArrayList highlight the selected row in red when the user clicked on the row. However, I also required the position of that click outside of the ArrayAdapter class.

The only way I could seem to do this is by adding an onClickListener, however this is were the issues began, although this solved my issue of getting the position the user click on, the row highlighting now seems to get overridden.

So basically my issue is allowing both selected rows to be highlighted and position to be passed to a variable outside of the ArrayAdapter class, please see my code below:

Array Adapter Class:

public class Shop extends ListActivity
{
    private static class MyAdapter extends ArrayAdapter<String> 
    {
        private ArrayList<String> data1, data2, data3, data4;

        public MyAdapter(Context context, int resource, int textViewResourceId, ArrayList<String> data1, ArrayList<String>  data2, ArrayList<String>  data3, ArrayList<String>  data4) 
        {
            super(context, resource, textViewResourceId, data1);
            this.data1 = data1;
            this.data2 = data2;
            this.data3 = data3;
            this.data4 = data4;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) 
        {
            View v = super.getView(position, convertView, parent);
            TextView t1 = (TextView) v.findViewById(R.id.data1);
            t1.setText(data1.get(position));
            TextView t2 = (TextView) v.findViewById(R.id.data2);
            t2.setText(data2.get(position));
            TextView t3 = (TextView) v.findViewById(R.id.data3);
            t3.setText(data3.get(position));
            TextView t4 = (TextView) v.findViewById(R.id.data4);
            t4.setText(data4.get(position));
            spnCharacters.setVisibility(View.GONE);

            Iterator<Integer> iterator = unavailableItem.iterator();
            while (iterator.hasNext())
            {
                int NotAvailable = iterator.next();
                if(position == NotAvailable)
                {
                    v.setBackgroundColor(Color.rgb(170, 170, 170));
                }
            }
            if(unavailableItem.size() == 1)
            {
                if(position == unavailableItem.get(0))
                {
                    v.setBackgroundColor(Color.rgb(170, 170, 170));
                }
            }
            if (position == 0) 
            {
                v.setBackgroundResource(android.R.drawable.title_bar);
            }

            v.setOnClickListener(new OnClickListener() 
            {
                @Override
                public void onClick(View v) 
                {
                    currentPositon = position;
                    if(data2.get(currentPositon).equals("0"))
                    {
                        btnSell.setEnabled(false);
                    }
                    else
                    {
                        btnSell.setEnabled(true);
                    }
                }
            });

            return v;
        }
    }

    private void NeedPosition()
    {
        int position = // need ArrayAdapter exact position here
    }
}   

ArrayAdapter XML:

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

    <TextView
        android:id="@+id/data1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight="1.5"
        android:gravity="center_horizontal"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/data2"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight="0.5"
        android:gravity="center_horizontal"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/data3"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight="0.5"
        android:gravity="center_horizontal"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/data4"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="5dp"
        android:layout_weight="0.5"
        android:gravity="center_horizontal"
        android:textColor="#FFFFFF" />

</LinearLayout>

List View XML:

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/linearButtons"
    android:layout_above="@+id/linerBuyBtns" 
    android:layout_marginTop="5dp"
    android:layout_marginBottom="5dp"
    android:listSelector="@drawable/list_selector">
</ListView>
  • 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-15T11:19:05+00:00Added an answer on June 15, 2026 at 11:19 am

    ListActvity has its own way to manage cell click.

    protected void onListItemClick (ListView l, View v, int position, long id)
    

    This method will be called when you click on an row of the ListView. As you can see the second paramter is the position you need

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

Sidebar

Related Questions

I have created custom cell in which there are n number of image views.
I have created a custom scroll. In which I am shifting the contents right
I have created an ArrayList (Java) of my custom class objects with a size
I have created a custom Array Adapter to bind a custom row that contains
I have created an arraylist that is made up of custom objects. Basically the
I have created a custom listview which has Image + Text + checkbox. How
I have created a custom Comparator to sort an ArrayList of Strings. I have
I have created a custom listView with the row as follows: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
I have created custom drawable marker which uses canvas to draw bounds. Everything works
I have a custom listview adapter which contains ArrayList as a member. Each game

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.