1. Download our Official Android App: Forums for Android!

Android AlertDialog View Help

Discussion in 'Introductions' started by Richmond, May 31, 2011.

  1. Richmond

    Richmond Lurker
    Thread Starter
    Rank:
    None
    Points:
    25
    Posts:
    1
    Joined:
    Aug 20, 2010

    Aug 20, 2010
    1
    0
    25
    Hello,
    I have an Android AlertDialog with an XML layout that in the interest of better visibility sets the background to white and the textColor to black. This works fine until I remove the android:text="myMessage" entry and try to setMessage in Java to something meaningful. The meaningful message gets set and displayed fine but I lose the white background with black text... Can anybody help explain what's going on here (starting to pull my hair out!)? I have included the code below.
    Thank you so much in advance,
    Ron

    XML layout:
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white">
    <LinearLayout
    android:id="@+id/lin_lay"
    android:eek:rientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp">
    <TextView android:id="@+id/help_text"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:textSize="20sp"
    android:textColor="@color/black">
    </TextView>
    </LinearLayout>
    </ScrollView>

    Java Snippet:
    private AlertDialog showHelp() {

    AlertDialog alertDialog = new AlertDialog.Builder(Game.this).create();
    View diagview = LayoutInflater.from(getBaseContext()).inflate(R.layout.help_dialog,
    (ViewGroup) findViewById(R.id.layout_root));
    alertDialog.setTitle("Help...");
    alertDialog.setView(diagview);
    alertDialog.setIcon(R.drawable.ic_help);
    alertDialog.setMessage(this.getString(help[helpIndex]));
    alertDialog.setIcon(R.drawable.ic_help);
    alertDialog.setButton("Close", new DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which) {
    } });

    alertDialog.show();
    return alertDialog;
     

    Advertisement

  2. olbriar

    olbriar  
    Moderator
    Rank:
     #8
    Points:
    2,013
    Posts:
    19,149
    Joined:
    Jun 19, 2010

    Jun 19, 2010
    19,149
    21,070
    2,013
    Male
    Land of Oz
    Welcome to Android Forums Richmond. I don't know exactly how to help you. Your best bet would be to follow this link: http://androidforums.com/
    .. scroll down and find your device.. enter that area of the forum and then ask your question. Again welcome aboard and good luck.
     
  3. scary alien

    scary alien not really so scary
    Moderator
    Rank:
     #7
    Points:
    2,138
    Posts:
    22,295
    Joined:
    Mar 5, 2010

    Mar 5, 2010
    22,295
    23,720
    2,138
    Male
    space alien ;)
    Indy
    Richmond,

    +1 to olbriar and welcome to AndroidForums!

    First off, your colon-letter-O's and color-letter-P's got converted to the smiley faces / emoticons in your code above. You can use the pound-sign / number-sign button in the message palette above or just wrap your code in CODE and /CODE blocks (surround the text in blue with brackets) so that the forum formatter won't monkey with what you want displayed.

    I took your code and tried to make a mini-project and I got it to display a little alert dialog, but I'm not sure what you were asking about that is not working.

    Here's the dialog I get and the main Java class that I used to test it (I had to do some minor tweaks since I didn't have all of the resources that your code references):

    popuptest.jpg

    Code (Text):
    1. package sa.testme;
    2.  
    3. import android.app.Activity;
    4. import android.app.AlertDialog;
    5. import android.content.DialogInterface;
    6. import android.os.Bundle;
    7. import android.view.LayoutInflater;
    8. import android.view.View;
    9. import android.view.ViewGroup;
    10.  
    11. public class testme extends Activity {
    12.     /** Called when the activity is first created. */
    13.     @Override
    14.     public void onCreate(Bundle savedInstanceState) {
    15.         super.onCreate(savedInstanceState);
    16.         setContentView(R.layout.main);
    17.        
    18.         showHelp();
    19.     }
    20.    
    21.  private AlertDialog showHelp()
    22.  {
    23.    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    24.    View diagview = LayoutInflater.from(getBaseContext()).inflate(R.layout.help_dialog,
    25.    (ViewGroup) findViewById(R.id.layout_root));
    26.     alertDialog.setTitle("Help...");
    27.     alertDialog.setView(diagview);
    28.     alertDialog.setIcon(R.drawable.help);
    29.     alertDialog.setMessage("this is a test");
    30.     alertDialog.setIcon(R.drawable.help);
    31.     alertDialog.setButton("Close", new DialogInterface.OnClickListener() {
    32.  
    33.    public void onClick(DialogInterface dialog, int which) {
    34.    } });
    35.  
    36.    alertDialog.show();
    37.     return alertDialog;  
    38.   }
    39. }
    Also, there is a website called stackoverflow.com that is a wonderful resource for asking and answering questions. I've only posted one question out there (no answers yet, lol), but there's some very knowledgeable folks who might be able to help you. (or a well-crafted Google search may very well take you to one of the answers already posted there).

    Also, a good alternative forum here on AF is http://androidforums.com/application-development/, so hopefully, someone over there might be able to help you too.

    Anyway, I can help make some further tweaks tomorrow evening if you need.

    Hope that helps.

    Cheers!
     

Share This Page

Loading...