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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:46:49+00:00 2026-05-26T18:46:49+00:00

I have a list view, the contain is populated from a database. And I

  • 0

I have a list view, the contain is populated from a database. And I put a button on each row, when it’s clicked it shows an AlertDialog box.

I have no errors on my project, but the app crashes everytime I click the button for the AlertDialog box.

Here’s my code:

donate_now.setOnClickListener(new OnClickListener() {
 public void onClick(View view) {
   AlertDialog.Builder alertbox = new AlertDialog.Builder(ProjectsList.this);
   alertbox.setTitle("SMS");
   alertbox.setMessage (Html.fromHtml(("Ihr SMS wird vorbereitet. Bitte 
                        bestätigen Sie mit 'Ok' und senden Sie danach die SMS ab! 
                        <p><small>Sie helfen dem Projekt mit " +mPriceIndex + ". 
                        Betrag je SMS zzgl. Transport. Der Betrag abzüglich 17 Cent 
                        geht direkt an die Partner-Organisation.")));                                                   
 alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
 public void onClick(DialogInterface arg0, int arg1) {
    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
    sendIntent.putExtra("address", mShortcodeIndex); 
    sendIntent.putExtra("sms_body", mKeywordIndex); 
    sendIntent.setType("vnd.android-dir/mms-sms");
    startActivity(sendIntent);
   }   
  });
  alertbox.show();

Can anybody help me analyze where do I go wrong?

Here’s the debug:

11-14 10:38:37.834: E/AndroidRuntime(509): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44c1e1b0 is not valid; is your activity running?
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewRoot.setView(ViewRoot.java:468)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.Dialog.show(Dialog.java:239)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
11-14 10:38:37.834: E/AndroidRuntime(509):  at spendino.de.ProjectsList$MySimpleCursorAdapter$2.onClick(ProjectsList.java:213)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.View.performClick(View.java:2364)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.View.onTouchEvent(View.java:4179)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.View.dispatchTouchEvent(View.java:3709)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.os.Looper.loop(Looper.java:123)
11-14 10:38:37.834: E/AndroidRuntime(509):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-14 10:38:37.834: E/AndroidRuntime(509):  at java.lang.reflect.Method.invokeNative(Native Method)
11-14 10:38:37.834: E/AndroidRuntime(509):  at java.lang.reflect.Method.invoke(Method.java:521)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-14 10:38:37.834: E/AndroidRuntime(509):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-14 10:38:37.834: E/AndroidRuntime(509):  at dalvik.system.NativeStart.main(Native Method)

Here’s the full activity code:

public class ProjectsList extends Activity implements OnItemClickListener{
    /** Called when the activity is first created. */

    ListView listView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.projects_list);

        doSync();
        ListView listView = (ListView) findViewById(R.id.lstText);
        listView.setOnItemClickListener(this);
        listView.setAdapter(new MySimpleCursorAdapter(this, R.layout.listitems,
                managedQuery(Uri.withAppendedPath(Provider.CONTENT_URI,
                        Database.Project.NAME), new String[] { BaseColumns._ID,
                        Database.Project.C_PROJECTTITLE,
                        Database.Project.C_SMALLIMAGE, Database.Project.C_PROJECTDESCRIPTION, Database.Project.C_ORGANIZATIONTITLE, Database.Project.C_DONATIONAMOUNT, Database.Project.C_KEYWORD, Database.Project.C_PRICE, Database.Project.C_SHORTCODE}, null, null, null),
                new String[] { Database.Project.C_PROJECTTITLE,
                        Database.Project.C_SMALLIMAGE, Database.Project.C_PROJECTDESCRIPTION, Database.Project.C_ORGANIZATIONTITLE, Database.Project.C_DONATIONAMOUNT}, new int[] {
                        R.id.txt_title, R.id.image, R.id.txt_list_desc, R.id.txt_org, R.id.btn_amount}));

    }

    public void onItemClick(AdapterView<?> l, View v, int position, long id) {
        Intent listIntent = new Intent(this, DetailsActivity.class);
        listIntent.putExtra("spendino.de.ProjectDetail.position",position);
        listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                Provider.CONTENT_URI, Database.Project.NAME), Long
                .toString(id)));
        startActivity(listIntent);

    }

    /*
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case R.id.ui_menu_sync:
            doSync();
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }
*/
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu, menu);
        return true;
    }

    void doSync() {
        Intent serviceIntent = new Intent(this, Sync.class);
        startService(serviceIntent);
    }


    class MySimpleCursorAdapter extends SimpleCursorAdapter {

        Context context=null;
        ImageLoader loader = null;
        private LayoutInflater mInflater = null;
        private int mProjectNameIndex = -1;
        private int mOrgNameIndex = -1;
        private int mDescIndex = -1;
        private int mDonationIndex = -1;
        private int mSmallImageIndex = -1;
        private int mKeywordIndex = -1;
        private int mPriceIndex = -1;
        private int mShortcodeIndex = -1;



        public MySimpleCursorAdapter(Context context, int layout, Cursor c,
                String[] from, int[] to) {
            super(context, layout, c, from, to);
            loader = new ImageLoader(context);
            this.context = context;

            mInflater = getLayoutInflater();    
            mProjectNameIndex = c.getColumnIndexOrThrow(Database.Project.C_PROJECTTITLE);
            mOrgNameIndex = c.getColumnIndexOrThrow(Database.Project.C_ORGANIZATIONTITLE);
            mDescIndex = c.getColumnIndexOrThrow(Database.Project.C_PROJECTDESCRIPTION);
            mDonationIndex = c.getColumnIndexOrThrow(Database.Project.C_DONATIONAMOUNT);
            mSmallImageIndex = c.getColumnIndexOrThrow(Database.Project.C_SMALLIMAGE);
            mKeywordIndex = c.getColumnIndexOrThrow(Database.Project.C_KEYWORD);
            mPriceIndex = c.getColumnIndexOrThrow(Database.Project.C_PRICE);
            mShortcodeIndex = c.getColumnIndexOrThrow(Database.Project.C_SHORTCODE);

        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View convertView = mInflater.inflate(R.layout.listitems, null);
            convertView.setClickable(true);
            convertView.setFocusable(true);
            convertView.setBackgroundResource(android.R.drawable.menuitem_background);
            //convertView.setOnItemClickListener(ProjectsList.this);

            convertView.setOnClickListener(new OnClickListener() {
                 public void onClick(View view) {

                     /*
                  Intent myIntent = new Intent(view.getContext(), DetailsActivity.class);
                  String position = null;
                myIntent.putExtra("spendino.de.ProjectDetail.position",position);
                  long id = 0;
                myIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                            Provider.CONTENT_URI, Database.Project.NAME), Long
                            .toString(id)));
                  view.getContext().startActivity(myIntent);
                 }
                });*/

            } 
                  });   




            return convertView;
        }

        protected void onItemClick(AdapterView<?> l, View v, int position, long id) {
            Intent listIntent = new Intent(ProjectsList.this, DetailsActivity.class);
            listIntent.putExtra("spendino.de.ProjectDetail.position",position);
            listIntent.setData(Uri.withAppendedPath(Uri.withAppendedPath(
                    Provider.CONTENT_URI, Database.Project.NAME), Long
                    .toString(id)));
            startActivity(listIntent);}

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            // Get your views from 'view'
            TextView projectTextView = (TextView) view.findViewById(R.id.txt_title);
            TextView orgTextView = (TextView) view.findViewById(R.id.txt_org);
            TextView descTextView = (TextView) view.findViewById(R.id.txt_list_desc);
            ImageView someImageView = (ImageView) view.findViewById(R.id.image);
            Button donate_now = (Button) view.findViewById(R.id.btn_donate);
            Button btn_amount = (Button) view.findViewById(R.id.btn_amount);
            donate_now.setFocusable(true);
            donate_now.setClickable(true);
            // Set the data
            projectTextView.setText(cursor.getString(mProjectNameIndex));
            orgTextView.setText("von " + cursor.getString(mOrgNameIndex));
            descTextView.setText(Html.fromHtml(cursor.getString(mDescIndex)+"..."));
            btn_amount.setText("Summe Spende: " + cursor.getString(mDonationIndex)+" €");

            donate_now.setOnClickListener(new OnClickListener() {
                 public void onClick(View view) {


                     AlertDialog.Builder alertbox = new AlertDialog.Builder(view.getContext());
                                            alertbox.setTitle("SMS");
                                            alertbox.setMessage (Html.fromHtml(("Ihr SMS wird vorbereitet. Bitte bestätigen Sie mit 'Ok' und senden Sie danach die SMS ab! <p><small>Sie helfen dem Projekt mit " +mPriceIndex + ". Betrag je SMS zzgl. Transport. Der Betrag abzüglich 17 Cent geht direkt an die Partner-Organisation.")));


                                            alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {

                                                public void onClick(DialogInterface arg0, int arg1) {
                                                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                                                    sendIntent.putExtra("address", mShortcodeIndex); 
                                                    sendIntent.putExtra("sms_body", mKeywordIndex); 
                                                    sendIntent.setType("vnd.android-dir/mms-sms");
                                                    startActivity(sendIntent);
                                                }   

                                    });
                                            alertbox.show();

            } 
                  });   
            loader.DisplayImage(cursor.getString(mSmallImageIndex ), context, someImageView);      
        }


        public void setViewImage(ImageView v, String value) {
            v.setTag(value);
            loader.DisplayImage(value, context, v);
        }
    }


}
  • 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-26T18:46:49+00:00Added an answer on May 26, 2026 at 6:46 pm

    You need to give the proper context to the alertDialog which must be the current activity context.So you need to declare a context for activity.

    //At the beginning of class where you declare the Listview
    ListView lv;
    Context ctx = this;
    

    And in your method.

    donate_now.setOnClickListener(new OnClickListener() {
                 public void onClick(View view) {
    
    
                     AlertDialog.Builder alertbox = new AlertDialog.Builder(ctx);
                                            alertbox.setTitle("SMS");
                                            alertbox.setMessage (Html.fromHtml(("Ihr SMS wird vorbereitet. Bitte bestätigen Sie mit 'Ok' und senden Sie danach die SMS ab! <p><small>Sie helfen dem Projekt mit " +mPriceIndex + ". Betrag je SMS zzgl. Transport. Der Betrag abzüglich 17 Cent geht direkt an die Partner-Organisation.")));
    
    
                                            alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
    
                                                public void onClick(DialogInterface arg0, int arg1) {
                                                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                                                    sendIntent.putExtra("address", mShortcodeIndex); 
                                                    sendIntent.putExtra("sms_body", mKeywordIndex); 
                                                    sendIntent.setType("vnd.android-dir/mms-sms"); 
    
                                                    startActivity(sendIntent);
                                                }   
    
                                    });
                                            alertbox.show();
    
            } 
                  });   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my winforms app, I have a list view control that is populated with
I have two activities. In activity1 , I have list view which is populated
I have created a custom listview that is populated using a row.xml file. Each
I have a list view contains 100+ rows. every time the user opens the
I have a listview that is loaded with a list of objects that contain
I have list view and its adapter stored as global variables. I am not
In my application, I have list view. Selecting another item in it, triggers an
I have a list view of Hotels and I want when the user clicks
I have a list view control which at the moment only allows one item
I have a list view that is periodically updated (every 60 seconds). It was

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.