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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:39+00:00 2026-06-13T08:43:39+00:00

I’ve look in the android documentation on how to implement alertdialog with a xml

  • 0

I’ve look in the android documentation on how to implement alertdialog with a xml layout

here is the documentation

when i run the program and click the todo button the program crashes can anyone help?

here’s my source code:

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class StartMoving extends Activity implements OnClickListener {

    Button todo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start_moving);

        todo = (Button) findViewById(R.id.bTodo);

        todo.setOnClickListener(this);

    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.bTodo:
            AlertDialog.Builder builder;
            AlertDialog alertDialog;

            Context mContext = getApplicationContext();
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.to_do_list, null);


            builder = new AlertDialog.Builder(mContext);
            builder.setView(layout);
            alertDialog = builder.create();
            alertDialog.show();
            break;

        default:
            break;
        }
    }

}

here’s the xml file named to_do_list.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"
    android:weightSum="100" >

    <ScrollView
        android:id="@+id/svTips"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="87" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tvTipsTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dp"
                android:text="@string/tips"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/tvtmb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/two_months_before"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvtmbSAP"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tmb_sort_and_purge"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvtmb_sap_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/tmb_sap_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvtmbR"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tmb_research"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvtmb_r_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/tmb_r_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvtmbCAMB"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/tmb_create_a_moving_builder"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvtmb_camb_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/tmb_camb_content" />

            <TextView
                android:id="@+id/tvswb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/six_weeks_before"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvswb_ordersupplies"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/swb_order_supplies"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvswb_os_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/swb_os_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvswb_use_it_or_lose_it"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/swb_use_it_or_lose_it"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvswb_uioli_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/swb_uioli_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvswb_take_measurement"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/swb_take_measurement"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvswb_tm_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/swb_tm_content" />

            <TextView
                android:id="@+id/tvomb"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/one_month_before"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_choose_your_mover_and_confirm_the_arragements"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_choose_your_mover_and_confirm_the_arragements"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_cymacta_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_cymacta_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_begin_packing"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_begin_paking"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_bp_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_bp_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_label"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_l_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_l_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_separate_values"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_separate_values"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_sv_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_sv_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_do_a_change_of_address"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_do_a_change_of_address"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_dacoa_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_dacoa_content" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <CheckBox
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/tvomb_notify_important_parties"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/omb_notify_all_important_parties"
                    android:textStyle="bold" />
            </LinearLayout>

            <TextView
                android:id="@+id/tvomb_naip_content"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:text="@string/omb_naip_content" />
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="13"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/bReturntoTop"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="50"
            android:text="Go back to top" />

        <Button
            android:id="@+id/bgoto"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="50"
            android:text="Go to" />
    </LinearLayout>

</LinearLayout>

this is what the logcat shows

enter image description here

  • 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-13T08:43:39+00:00Added an answer on June 13, 2026 at 8:43 am

    It seems that I’ve been reading the button from the Context and not from the alertDialog. The solution was to create a View that will be set as View for the AlertDialog and declare a button and set it as a child for the View.

    final View view;
    LayoutInflater inf = LayoutInflater.from(StartMoving.this);
    view = inf.inflate(R.layout.rename, null);
    final EditText newname = (EditText) view.findViewById(R.id.etNewRoomName);
    final Button todo = (BUtton) view.findViewById(R.id.bTodo);
    
    new AlertDialog.Builder(StartMoving.this)
    .setView(view)
    .setTitle("Rename")
    .setMessage("Enter new name for room " + currentRoom)
    .show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an XML file, the creators of it stuck in a bunch social
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.