• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Android AlertDialog View Help

Richmond

Lurker
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:orientation="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;
 
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.
 
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:
package sa.testme;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class testme extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        showHelp();
    }
    
 private AlertDialog showHelp()
 {
   AlertDialog alertDialog = new AlertDialog.Builder(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.help);
    alertDialog.setMessage("this is a test");
    alertDialog.setIcon(R.drawable.help);
    alertDialog.setButton("Close", new DialogInterface.OnClickListener() {

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

   alertDialog.show();
    return alertDialog;   
  }
}

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!
 
Back
Top Bottom