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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:59:39+00:00 2026-06-18T18:59:39+00:00

I have a custom ListView in which there is a textview and an image.

  • 0

I have a custom ListView in which there is a textview and an image. I have set onclicklistener for imageview in my customlistadapter class, so I need to make some changes in main layout when the image is clicked. See the below code for reference…

MainActivity.java

hmDataList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long arg1) {

            DataFields dataField = (DataFields) hmDataList
                    .getItemAtPosition(position);
            ImageView v = (ImageView) view.findViewById(R.id.hmFieldDeleteImage);
            RelativeLayout mainRL = (RelativeLayout)view.findViewById(R.id.hmFieldMainRL);
            }

}

CustomListAdapter.java

    public View getView(int position, View convertView, ViewGroup parent) {
        holder = null;
        DataFields rowItems = (DataFields) getItem(position);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.home_field_row, null);
            holder = new ViewHolder();
            holder.mName = (TextView) convertView.findViewById(R.id.hmFieldName);
            holder.mDeleteImage = (ImageView)convertView.findViewById(R.id.hmFieldDeleteImage);

            convertView.setTag(holder);

            holder.mDeleteImage.setTag(position);
            final View clickView = convertView;
            holder.mDeleteImage.setOnClickListener(new ImageView.OnClickListener() {

                @Override
                public void onClick(final View view) {
                    count++;
                    clickView.setBackgroundColor(color.list_row_bg);
                    //
                    //Some changes has to be made for the main activity's layout
                    //
                }
            });
        }

        else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mName.setText(rowItems.getName());

        return convertView;
    }

list_row.xml

<TextView
    android:id="@+id/hmFieldName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:gravity="left"
    android:shadowColor="#000000"
    android:shadowDx="0"
    android:shadowDy="0"
    android:shadowRadius="2"
    android:text="@string/no_data"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="#F2F2F2" />

<ImageView
    android:id="@+id/hmFieldDeleteImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:contentDescription="@string/right_arrow"
    android:src="@drawable/delete" />

activity_main.xml has some widgets which are hidden, so I need to unhide them when the Image in the custom ListView is clicked.

To put it simple, Is there any way to update the gui of main activity from other class?
Any kind of help or example or reference is much appreciated. Thanks !

  • 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-18T18:59:40+00:00Added an answer on June 18, 2026 at 6:59 pm

    Here is a good way to do it:

    In your MainActivity.java add :

    public onClickListener mListener = new OnClickListener(){
            @Override
                public void onClick(final View view) {
                    count++;
                    view.setBackgroundColor(color.list_row_bg);
                    //
                    //Some changes has to be made for the main activity's layout
                    //
    
                   // Here you can delete add or do anything to your views
                }
    
      };
    

    and when you create a new CustomListAdapter object:

    CustomListAdapter adapter = new .....;
    adapter.setActivity(this);
    

    and In your CustomListAdapter.java add :

     private MainActivity mActivity;
    
    
     public void setActivity(MainActivity activity){
              mActivity = activity;
     }
    

    and In your getView method:

    public View getView(int position, View convertView, ViewGroup parent) {
    holder = null;
    DataFields rowItems = (DataFields) getItem(position);
    LayoutInflater inflater = (LayoutInflater) context
    .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.home_field_row, null);
    
                 ....  Same Code
    
            holder.mDeleteImage.setTag(position);
            final View clickView = convertView;
    // use this code
            holder.mDeleteImage.setOnClickListener(mActivity.mListener);
        }
    
        else {
            holder = (ViewHolder) convertView.getTag();
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom ListView in which there are 2 buttons and a textview
I have a Custom ListView which has an ImageView and a TextView. and i
I am trying to make a listview which has a textview and an imageview
This is my setup. I have a custom ListView with some fancy headers, which
I have a Custom ListView in my application and it has some TextView s
I have a custom adapter for my ListView which has multiple TextViews. I want
I have a ListView which contains custom rows. This custom row has following UI
I have an activity with a ListView which is populated through a custom ArrayAdapter.
I have a custom cell for my listview which has TEXT NUMBER - which
I have a custom control containing a ListView control, which displays files in the

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.