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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:38:09+00:00 2026-06-07T18:38:09+00:00

Copying other people’s code that I only half understand, I have succeeded in making

  • 0

Copying other people’s code that I only half understand, I have succeeded in making a listview, each element of which contains three TextViews and a CheckBox.

The code involves the following two xml files. First “customrowview.xml”:

<?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:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="142dp"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
            <TextView android:id="@+id/text1"         

                android:layout_width="match_parent"         
                android:layout_height="fill_parent"/>
            <TextView android:id="@+id/text2"         

                android:layout_width="match_parent"         
                android:layout_height="fill_parent"/>
            <TextView android:id="@+id/text3" 

                android:layout_width="match_parent" 
                android:layout_height="wrap_content"/>

        </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="right" >



    <CheckBox
        android:id="@+id/checkbox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />
        <Button
            android:id="@+id/editbut"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Edit" />
        </LinearLayout>
    </LinearLayout>



</LinearLayout>

Then “customlistview.xml”:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ListView android:id="@id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000fff"
    android:layout_weight="2"
    android:drawSelectorOnTop="false">
    </ListView>
<TextView  android:id="@id/android:empty"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFff00"
    android:text="No data"
    />
</LinearLayout>

I get access to the list via:

listView = (ListView) findViewById(R.id.mylist);

The code also involves:

    SimpleAdapter adapter = new SimpleAdapter(
            this,
            list,
            R.layout.custom_row_view,
            new String[] {"label","daysordate","time"},
            new int[] {R.id.text1,R.id.text3, R.id.text2}
            );
listView.setAdapter(adapter);

Now what I want to do is something like listView.setlistenerforbuttonwithinlist() !

But can not work out how to do it. I know there have been related questions on SO before, but I can not understand the answers 🙁

EDIT: After seeing azgolfers answer… I made a custom adapter as follows:

public class myadapter extends SimpleAdapter
{
    LayoutInflater mLayoutInflater;


    public void myadapter(Context context) 
    {
        mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View view = null;

        if (convertView != null)
        {
            view = convertView;
        } 
        else 
        {      
            view = mLayoutInflater.inflate(R.layout.custom_row_view, null);
        }

        Button buttonEdit = (Button) view.findViewById(R.id.editbut);

        buttonEdit.setOnClickListener(new OnClickListener()
        {   
            public void onClick(View arg0)
            {
                Log.i("xx","Button pressed!");
            }
        });

        return super.getView(position, convertView, parent);
    }

    public myadapter(Context context, List<? extends Map<String, ?>> data,int resource, String[] from, int[] to) 
    {
        super(context, data, resource, from, to);
        // TODO Auto-generated constructor stub
    }

}

Unfortunatly this crashes at the line

view = mLayoutInflater.inflate(R.layout.custom_row_view, null);

With a null pointer exception… not sure why 🙁

  • 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-07T18:38:10+00:00Added an answer on June 7, 2026 at 6:38 pm

    First, you need to extend your own Adapter, probably from an ArrayAdapter. ArrayAdapter has a method called getView that you will need to override and provide the UI for a listview row at a certain position. e.g.

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = null;
            if (convertView != null) {
                view = convertView;
            } else {
                view = mLayoutInflater.inflate(R.layout.custom_row_view, null);
            }
            Button buttonEdit = (Button) view.findViewById(R.id.editbut);
            buttonEdit.setOnClickListener(...);
        }
    

    In getView(), since you are building the UI of the row, you have a chance here to set the click handler on your button.

    Also, you also need to add this to your Button’s xml tag:

    android:focusable="false"
    android:focusableInTouchMode="false" 
    

    Without that, button inside a listview will not fire OnClick event when pressed.

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

Sidebar

Related Questions

I am trying to run code of copying files in other thread so that
People have been able to build PCRE (or a subset of) by copying the
I am copying code from website matplotlib and pasting into the Vim editor in
I'm copying ListViewItems from one ListView to another, sth. like: foreach (ListViewItem item in
I have problem with copying sdf file to WM emulator. My solution structure MyApp.DataLayer
I joined a team with greenfield code. When I joined, they did not have
I was just wondering if there is a way to prevent people from copying
I have a MVC 3.0 .Net 4.0 Razor application that is periodically giving me
Before the performance people tear my head off: yes, I have done profiling before
Why do people define a private copy constructor? When is making the copy constructor

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.