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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:54:35+00:00 2026-05-18T00:54:35+00:00

I have a custom listview in which one textview and one checked box is

  • 0

I have a custom listview in which one textview and one checked box is in each row.
When I click the ckeckbox, I want to add the value from TextView to database and to display a Toast message in the view. The database insertion is working fine. But the application is stopping suddently, and the Toast message is not shown in the view.

 public class Favourites extends Activity 
 {
     @Override
     public void onCreate(Bundle savedInstanceState)
     {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_list);
        ListView listitems = (ListView) findViewById(R.id.ListView_01);
        listitems.setAdapter(new EfficientAdapter(this));
     }
     private static class EfficientAdapter extends BaseAdapter
     {
        //imp
        public View getView(int position,  View convertView, ViewGroup parent) 
        {

              if (convertView == null)
              {
                  int itemId=SubListIdList.get(position);
                  TextView text = (TextView) convertView.findViewById(R.id.TextView_02);
                  CheckBox star = (CheckBox) convertView.findViewById(R.id.star);
                  star.setOnCheckedChangeListener(new OnCheckedChangeListener() 

                  {

                       @Override
                       public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)
                       {
                           Favourites f=new Favourites();
                           query="UPDATE "+SUB_TABLE_NAME+" SET FavoriteIndicator='Y' WHERE SubListID="+itemId;
                           db.execSQL(query);   
                           Toast.makeText(f, "Insertion successfull!", 1).show();
                       }
                 }
           }
       }
    }
}

Please help me…. Thank you…

  • 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-05-18T00:54:36+00:00Added an answer on May 18, 2026 at 12:54 am

    Give the Toast notification your main activitiy’s context to display it. I’m not quite sure why you are instantiating your activity again in the onCheckedChanged() method but I guess you were trying to pass your Toast a context with that. Try it this way.

    Context ctx = null;
    
    onCreate(Bundle bundle) {
        super.onCreate(bundle);
        // more stuff
        ctx = getApplication();
    
        // even more stuff
        @Override
        public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
            query="UPDATE "+SUB_TABLE_NAME+" SET FavoriteIndicator='Y' WHERE" +
            " SubListID="+itemId;
            db.execSQL(query);   
            Toast.makeText(ctx, "Insertion successfull!", 4000).show();
        }
    }
    

    And please don’t set your Toast display time to one millisecond that won’t help you. The time parameters is set in milliseconds.

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

Sidebar

Related Questions

I have one custom ListView which contains one ImageView and one TextView, and I
I have a listview which I am populating with a custom SimpleCursorAdapter, each row
I have a custom listView with editText in each row to carry value entered
I have a listview with custom rows and that extends SimpleAdapter. Each row consist
I have one custom ListView called AreasListView which I've included in the XML file.
I have a custom listview which display an image, textview and radio button. I
I have a custom listview which changes size when one of the rows is
Basically, I have a custom ListView in which each item looks like: <LinearLayout> <Table>
I have created a custom listview that is populated using a row.xml file. Each
I have a listView with custom objects defined by the xml-layout below. I want

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.