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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:31:54+00:00 2026-06-02T12:31:54+00:00

I have a listview and I have inflate it with a custom layout containing

  • 0

I have a listview and I have inflate it with a custom layout containing 1 ImageView, 2 TextView and 1 Button. I want to change the button background when I click on a listview item , but I don’t be able to perform it. Can someone help me, please? Thank you so much in advance.

enter image description here

row_segnalibro.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/LinearLayout01"
     android:orientation="horizontal"
     android:layout_width="match_parent" android:layout_height="50dp" >

<ImageView android:id="@+id/ImageView01" android:src="@drawable/star" 
android:layout_height="40dp"
    android:layout_width="40dp"
    android:enabled="false"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    android:paddingLeft="10dp"  />

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02"
    android:orientation="vertical"
    android:layout_width="220dp" android:layout_height="match_parent">

<TextView 
    android:id="@+id/tvRow1"
    android:layout_width="220dp"
    android:layout_height="wrap_content"   
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    android:paddingLeft="10dp"    
    android:paddingTop="5dp"
    android:textColor="#0967AD"
    android:textStyle="bold"
    />
<TextView 
    android:id="@+id/tvRow2"
    android:layout_below="@id/tvRow1"
    android:layout_width="220dp"
    android:layout_height="wrap_content"   
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    android:paddingLeft="10dp"    
    android:textColor="#0967AD"
    android:textStyle="bold"
 />
</RelativeLayout>
<Button 
    android:id="@+id/butt_segnalib"
    android:background="@drawable/freccia_o"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:layout_width="20dp"
    android:layout_height="20dp"
    android:layout_gravity="center" />

Segnalibro.java

  public class Segnalibro extends ListActivity{
            super.onCreate(savedInstanceState);
        setContentView(R.layout.segnalibro);

         lv = (ListView) getListView();         
 .....some code
      MySimpleCursorAdap myadap = new MySimpleCursorAdap(getApplicationContext(),R.layout.rowlayout_segnalibro,curr,campi, to);
         lv.setAdapter(myadap);
         lv.setClickable(true); 

          lv.setOnItemClickListener( new  OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View v,int position, long arg3) {
                    Log.i("","I have clicked on item "+position);   

            }        
        });

MySimpleCursorAdap.java

      public class MySimpleCursorAdap extends SimpleCursorAdapter{

        public MySimpleCursorAdap(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        this.mLayout = layout;
        this.curr = c;
                 this.cont = context;
          }

 public void bindView(View view, Context context, final Cursor cursor) {

   ....some code

 /*       Button butt = (Button) view.findViewById(R.id.butt_segnalib); 
          butt.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
     .....code to change the background
     }
        }); */
  }

in MySimpleCursorAdap I can get the Button with the method findViewById, how I can to do it in the class Segnalibro?

  • 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-02T12:31:58+00:00Added an answer on June 2, 2026 at 12:31 pm

    Ok.. so basically you need a state list for acheiving it.. see this to know how to create it.. and then set it as background of your button..

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

Sidebar

Related Questions

I have a ListView with a custom footer set via list.addFooterView(getLayoutInflater().inflate(R.layout.list_footer_view, null, true), null,true);
i have a listView with a custom BaseAdapter.Every list item has a clickable button.
I want to create a layout which contains TextView , Button and ListView here
I have a custom listView with a textView, editText and a Button on a
I have a custom listview which display an image, textview and radio button. I
I have a listview with a custom adapter. Each listview item has an ImageView.
I have a ListView powered by a custom adapter that dynamically changes the background
I have a ListView with a custom Adapter that creates rows containing TextViews that
I have a fairly complex layout (containing RelativeLayouts, TextViews and ImageViews) that I want
I am making a custom ListView of rows containing a CheckBox and a TextView

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.