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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:42:12+00:00 2026-06-12T07:42:12+00:00

I’m pretty new to Android and I need some guidance. I have two activities

  • 0

I’m pretty new to Android and I need some guidance.

I have two activities so far. The first one contains an ActionBar and a ListView. I want the ListView to be populated with rows containing a TextView and a CheckBox. The text is represented by an username read from a database.The ActionBar has buttons for actions: “new” and “delete”. “new” opens a new activity which adds a new user into the database, delete action should delete checked entries from the list and database. Screens:

Main activity: https://i.stack.imgur.com/S3y0r.jpg

Create profile activity: https://i.stack.imgur.com/IyKYA.jpg

To get these I used SQLiteHelper and a datasource for the database and a custom ArrayAdapter for the ListView. I have one problem and some concerns, listed below.

1 . The problem: when I add a new user, I can only see the changes in the ListView after I exit the app using the back button.

2 . Is a custom ArrayAdapter a good solution for this or should I use a CursorAdapter? When clicked, the list item should use the information associated with it into another activity/fragment. Below is my custom adapter. It works right now, but the next step is to implement the delete action, and i’m not entirely sure how I do that. This is where i need advice. Thank you!

    public class CustomUserAdapter extends ArrayAdapter<UserProfile>{

        ArrayList<UserProfile> users;
        private LayoutInflater inflater;

        public CustomUserAdapter(Context context, ArrayList<UserProfile> users) {
        // TODO Auto-generated constructor stub
        super(context, R.layout.users_list_row, users);
        this.users = users;
        inflater = LayoutInflater.from(context);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
        UserProfile user = users.get(position);
        CheckBox checkBox;
        TextView textView;

        if(convertView == null){
            convertView =  inflater.inflate(R.layout.users_list_row, null);
            checkBox = (CheckBox) convertView.findViewById(R.id.checkElement);
            textView = (TextView) convertView.findViewById(R.id.textElement);

            //tag row
            convertView.setTag(new UserHolder(textView, checkBox));
        } else {
            UserHolder userHolder = (UserHolder) convertView.getTag();
            checkBox = userHolder.getCheckBox();
            textView = userHolder.getUserText();
        }

        //tag checkbox
        checkBox.setTag(user);

        //checkbox listener
        checkBox.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            }
        });

        checkBox.setChecked(false);
        textView.setText(user.getUsername());

        return convertView;
            }
      }
  • 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-12T07:42:13+00:00Added an answer on June 12, 2026 at 7:42 am

    1) after changing your arraylist, remember to call “adapter.notifyDataSetChanged();” on your adapter which is linked with your list view

    2) an arrayadapter should work just fine. remember when you delete a contact from your arraylist, to call notfiydatasetchanged again on your adapter. Also keep in mind in order to delete an Sql entry of your objects, you will need an id or some sort of ID that you can reference to your SQLite database (id, auto increment is standard)

    here is an example for implementing listener on each item and deleting, using a dialog.

    list.setOnItemClickListener(new OnItemClickListener() {
    
            public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2, long arg3) {
                // TODO Auto-generated method stub
                AlertDialog.Builder dialog = new AlertDialog.Builder(ContactExampleActivity.this);
                dialog.setTitle("title");
                dialog.setMessage("message");
                dialog.setPositiveButton("delete", new DialogInterface.OnClickListener(){
                    public void onClick(DialogInterface dialog, int which) {
                        //delete from array and delete from sqlite database here
    
                        adapter.notifyDataSetChanged();
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.