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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:09:18+00:00 2026-05-26T17:09:18+00:00

I need to a make a dialog appear as soon as my program’s user

  • 0

I need to a make a dialog appear as soon as my program’s user makes a longclick on the screen (in any place of the screen)…

All the tutorials I’ve found so far only helped me to do the dialog box appear on a button-click, but that’s really not what I need.

Can someone help me with that?

My Code is right now as follows:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    /* In the onCreate() method, we need to set the content to our XML layout, 
     * extract the TabHost object, and call setup() on the TabHost 
     * (we need to do this because our Activity is not a TabActivity). */

    tabHost = (TabHost) findViewById(android.R.id.tabhost);

    tabHost.setup();
    tabHost.setOnTabChangedListener(this);

    //Next, we want to extract our ListView from the XML, set it to a member variable, and add some initial coordinates to its list adapter
    listView = (ListView) findViewById(R.id.list);
    listView.setEmptyView((TextView) findViewById(R.id.empty));

    // Random points on the geo list:
    List<GeoPoint> pointsList = new ArrayList<GeoPoint>();
    pointsList.add(new GeoPoint((int)(-30.03269*1E6), (int)(-51.225514*1E6)));
    pointsList.add(new GeoPoint((int)(41.89001*1E6), (int)(12.496948*1E6)));
    listView.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, pointsList));

    // add an onclicklistener to see point on the map
    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View view, int position, long id) {
            GeoPoint geoPoint = (GeoPoint) listView.getAdapter().getItem(position);
            if(geoPoint != null) {
                // have map view moved to this point
                setMapZoomPoint(geoPoint, 12);
                // programmatically switch tabs to the map view
                tabHost.setCurrentTabByTag(MAP_TAB_TAG);
            }
        }
    });

    // Then, we want to extract our MapView from the XML and set it to a member variable.
    mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    mapView.postInvalidate();




    final AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("make route");
    alert.setMessage("from:");

    // Set an EditText view to get user input 
    final EditText fromAddress = new EditText(this);
    alert.setView(fromAddress);

    alert.setMessage("to:");
    final EditText toAddress = new EditText(this);
    alert.setView(toAddress);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
      Editable value1 = fromAddress.getText();
      Editable value2 = toAddress.getText();
      // Do something with value!
      }
    });

     Editable value2 = toAddress.getText();


    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
      }
    });


    View layout = findViewById(R.id.layout);

    layout.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {
    alert.show();
            return false;
        }
    });

The layout:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout 
        android:id="@+id/layout"
        android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
        <TabWidget 
            android:id="@android:id/tabs"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" />
        <FrameLayout 
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent"
                android:id="@+id/main">
                <ListView 
                    android:id="@+id/list" 
                    android:layout_width="fill_parent"
                    android:layout_height="0dip" 
                    android:layout_weight="1" />
                <TextView 
                    android:id="@+id/empty" 
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" 
                    android:gravity="center"/>

            </LinearLayout>

            <RelativeLayout 
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/mainlayout" 
                android:orientation="vertical"
                android:layout_width="fill_parent" 
                android:layout_height="fill_parent">
                <com.google.android.maps.MapView
                    android:id="@+id/mapview" 
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent" 
                    android:clickable="true"
                    android:apiKey="MY KEY HERE" />
            </RelativeLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>

The Activity is a MapActivity , so am I right to think that I can’t implement a long click on a MapActivity?

  • 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-26T17:09:19+00:00Added an answer on May 26, 2026 at 5:09 pm

    For example you can set id for LineraLayout in layout file

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:id="@+id/layout">
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@string/hello" />
    
    </LinearLayout>
    

    and in activity add onLongClickListener

     public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            View layout = findViewById(R.id.layout);
    
            layout.setOnLongClickListener(new View.OnLongClickListener() {
    
                @Override
                public boolean onLongClick(View v) {
                    //show dialog box
                    return false;
                }
            });
        }
    

    //edit

    I think you should from AlertDialog.Builder create AlertDialog and after that show dialog.

    alert is your AlertDialog.Builder

    AlertDialog alert2 = alert.create();
    alert2.show() // you have to show AlertDialog, not AlertDialog.Builder
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make a transition screen, ou just put a dialog, because the
I am using jQuery dialog plugin because i need to make decision upon user
I need to make a WebCast presentation soon and need to do some whiteboarding
I need to make sure that user can run only one instance of my
I need to make a piece of C# code interact through COM with all
I need to make a custom dialog with 4 options but as far as
i need to make a page that will have a request dialog for a
I need to make a radiolist in bash script using dialog interface, for example
I need to make my custom dialog transparent. How can I do that?
I need some help on android.., apparently, I'm trying to make a progress dialog

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.