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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:05:50+00:00 2026-05-26T13:05:50+00:00

I want to implement Custom Dialog in Android. However , when I tried it

  • 0

I want to implement Custom Dialog in Android. However , when I tried it on my own I am unable to run my code.

I am getting an error in these statements in Eclipse:
1) Button button1main = (Button) findViewById(R.id.*btn1*);

2) TextView text = (TextView) dialog.findViewById(R.id.*txt3*);

My Android code is :

package com.example;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class Main2 extends Activity {

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

        Button button1main = (Button) findViewById(R.id.btn1);
        button1main.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Dialog dialog = new Dialog(Main2.this);
                dialog.setContentView(R.layout.maindialog);
                dialog.setTitle("This is my custom dialog box");
                dialog.setCancelable(true);

                TextView text = (TextView) dialog.findViewById(R.id.txt3);
                text.setText(R.string.lots_of_text); 

                Button button = (Button) dialog.findViewById(R.id.Button01);
                button.setOnClickListener(new OnClickListener() {

                    public void onClick(View v) {
                        finish();
                    }
                });

                dialog.show();
            }

        });
    } 
}

Here are my xml’s :
front.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">


  <TextView
     android:id="@+id/txt3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="This is my main activity, from here, I want to display a dialog, after the user clicked the button below this text."/>

  <Button
      android:layout_height="wrap_content"
      android:layout_below="@+id/txt3"
      android:layout_width="wrap_content"
      android:id="@+id/btn1"
      android:text="Hey! There is more..."/>

</RelativeLayout>

maindialog.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout>

  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" android:layout_height="wrap_content">

  <ScrollView>
    android:id="@+id/ScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="200px">

    <TextView>
      android:text="@+id/txt3"
      android:layout_width="wrap_content" android:layout_height="wrap_content">
    </TextView>

  </ScrollView>


  <Button>
    android:id="@+id/Button01"
    android:layout_below="@id/ScrollView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Cancel"
  </Button>

</RelativeLayout>

I am not able to run my code in Eclipse until I remove those red line errors in the above mentioned statements..Can someone help me ?

Thanks

  • 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-26T13:05:51+00:00Added an answer on May 26, 2026 at 1:05 pm

    You have errors in your xml syntax.

    <RelativeLayout>  <- this is wrong
        android:id="@+id/RelativeLayout01&quot; 
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">
    

    You need to remove “>” , this applies to all elements, not only relative layout

    <RelativeLayout
        android:id="@+id/RelativeLayout01&quot; 
        android:layout_width="fill_parent"  
        android:layout_height="fill_parent" 
        xmlns:android="http://schemas.android.com/apk/res/android">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to implement a custom error page, what i want to be able
I have implemented a custom dialog for my application. I want to implement that
I want to implement the own custom TextBox control in Asp.Net(C#). Please give me
I want to implement a custom trace listener like follows: public class TraceListener :
I'm trying to implement a DataGrid in ASP.NET, and want to achieve custom paging
I want to implement a custom user authentication system in my appengine app. I
I want to implement a Custom logger which logs all log entries to a
I am new to Flex programming. I want to implement a custom toolstrip for
I want to implement the Google custom search API with Greasemonkey, and so far
I want to implement a custom identity model in order to connect to 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.