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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:05:58+00:00 2026-06-18T09:05:58+00:00

I am new to Android, and the first project I am working on is

  • 0

I am new to Android, and the first project I am working on is putting players onto a team. I have a listview that grabs all of the players from a database. Each name is supposed to have a checkbox next to them and then there is a button at the bottom that is supposed to update the database. So far this is what I am getting.

http://dyp.im/W79JdmfIk

Here is my activity

 package com.example.sqllitetest;

 import android.app.AlertDialog;
 import android.app.ListActivity;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.support.v4.widget.ResourceCursorAdapter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.*;

public class Tester extends ListActivity {

MyAdapter mListAdapter;
PlayersDBAdapter mDbHelper;
private Button button;
private Context context = this;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mDbHelper = new PlayersDBAdapter(this);
    mDbHelper.open();
    Cursor myCur = mDbHelper.fetchAllPlayers();
    startManagingCursor(myCur);
    setContentView(R.layout.playertoteam);

   // registerForContextMenu(getListView());
   // ((Tester) context).setContentView(R.layout.playertoteam);
    //getListView().addFooterView(button);
    mListAdapter = new MyAdapter(Tester.this, myCur);
    setListAdapter((ListAdapter) mListAdapter);

    Button button = (Button) findViewById(R.id.alertBox);
    button.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            setResult(RESULT_OK);
            finish();
        }

    });

}


private class MyAdapter extends ResourceCursorAdapter {

    public MyAdapter(Context context, Cursor cur) {
        super(context, R.layout.playertoteam, cur);
    }

    @Override
    public View newView(Context context, Cursor cur, ViewGroup parent) {
        LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        return li.inflate(R.layout.playertoteam, parent, false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cur) {
        TextView tvListText = (TextView)view.findViewById(R.id.code);
        CheckBox cbListCheck = (CheckBox)view.findViewById(R.id.checkBox1);

        tvListText.setText(cur.getString(cur.getColumnIndex(mDbHelper.KEY_NAME)));
        cbListCheck.setChecked((cur.getInt(cur.getColumnIndex(mDbHelper.KEY_ID))==1? false:true));
    }




}
}

And here is my xml file

<?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="wrap_content"
android:orientation="vertical"
android:padding="6dip" >

 <Button
    android:id="@+id/alertBox"
    android:layout_alignParentBottom="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/confirm" />
  <RelativeLayout
            android:id="@+id/relativeLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="top" >
            <ListView
                android:id="@android:id/list"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@id/alertBox"
                />
            <TextView
                android:id="@+id/code"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

              <CheckBox android:id="@+id/checkBox1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:focusableInTouchMode="false"

                />

  </RelativeLayout>

</LinearLayout>

I would like to know how to remove the buttons from the rows and the check box that is underneath the main confirm button. Also I would like to know if this is the best way to do something like this, because, once again, I am new and I don’t know how to search for the correct methods.

  • 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-18T09:05:59+00:00Added an answer on June 18, 2026 at 9:05 am

    ResourceCursorAdapter creates views ,for every row of the ListView, that are inflated in newView() method. You are getting button in every row because of this reason.
    Soln: Create a separate xml defining the row layout for the ListView and inflate this new layout in the newView() method. And have only the button and ListView in main layout i.e. playertoteam.xml

    playertoteam.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="6dip" >
    
    <Button
        android:id="@+id/alertBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/confirm" />
    
    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_above="@id/alertBox" />
    
    </RelativeLayout>
    

    row_layout.xml

       <?xml version="1.0" encoding="utf-8"?>
       <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
    
      <TextView
        android:id="@+id/code"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true"/>
    
      <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false" 
        android:layout_alignParentRight="true"/>
    
     </RelativeLayout>
    

    You can find example for ListView here

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

Sidebar

Related Questions

First of all, I'm quite new to the Android and JAVA world (coming from
n00b here (first Android project). I have been given a custom video codec that
i am working on my first project with android and java and have very
I am currently working on an android project and I have an activity that
I'm building my first Android image, i noticed that compiling a new kernel is
when i am creating new android project from visual studio 2010 it gives the
I am currently working on an android project and have created a little test
I am working on an Android project in that i need to send the
I'm working on my first Android project, and I created a menu via the
I'm working on my first Android project, and I'm starting off by making a

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.