Can't display the dialog item

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Can't display the dialog item

Postby The_One_Neo » Wed Apr 08, 2009 7:11 am

Hi guys
In my app, i create a alertdialog, and load the resource from array.xml.
but i can't display the array item.


please help me :cry:
Attachments
1.PNG
1.PNG (7.27 KiB) Viewed 462 times
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Top

Postby WarrenFaith » Wed Apr 08, 2009 9:26 am

Than give us a little code snippet of array.xml and/or the way you create/call the dialog.

Can't help without the proper information :)
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Wed Apr 08, 2009 10:04 am

WarrenFaith wrote:Than give us a little code snippet of array.xml and/or the way you create/call the dialog.

Can't help without the proper information :)


public class MainActivity extends Activity{
protected Dialog onCreateDialog(int id) {
return new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.app_name)
.setItems(R.array.status_items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
OperaNormalItem(mCurItem, which);
}
})
.create();
}
}

<string-array name="status_items">
<item>"online"</item>
<item>"busy"</item>
<item>"outtolunch"</item>
</string-array>


if focus on it, it can display the text :cry:
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Wed Apr 08, 2009 10:18 am

This code is messy :)

JavaDoc of create():
Creates a AlertDialog with the arguments supplied to this builder. It does not Dialog.show() the dialog. This allows the user to do any extra processing before displaying the dialog. Use show() if you don't have any other processing to do and want this to be created and displayed.


Tried to call show() instead of create() ?
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Wed Apr 08, 2009 11:02 am

return new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.app_name)
.setItems(R.array.opear_normal_menu_items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
OperaNormalItem(mCurItem, which);
}
})
.show();

the app is crash...
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Wed Apr 08, 2009 4:00 pm

Ok, than 2 things:
First, clean up your source... it is awful to see what you are programming.
Second, open LogCat and post the error please... find it here: Eclipse -> Window -> Show View -> Other -> Android -> LogCat
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Postby The_One_Neo » Thu Apr 09, 2009 3:03 am

this is the error code from logcat
thread exiting with uncaught exception
(group=0x40010e28)

where we can get the error code about (group=0x40010e28) from the sdk?
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Thu Apr 09, 2009 7:47 am

If there is an uncaught exception, than you have to find the exception in your LogCat...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Thu Apr 09, 2009 9:19 am

i tested mycode

protected Dialog onCreateDialog(int id) {

if(id == app.CONTACT_NORMAL_FLAG)
{
return new AlertDialog.Builder(MainActivity.this)
.setTitle(R.string.app_name)
.setItems(R.array.opear_normal_menu_items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

/* User clicked so do some stuff */
String[] items = getResources().getStringArray(R.array.opear_normal_menu_items);
new AlertDialog.Builder(MainActivity.this)
.setMessage("You selected: " + which + " , " + items[which])
.show();
}
})
.create();
}
}

if you create your alertdialog in the onCreateDialog(), no need use show(), because you return this dialog and display

if you create dialog in other function you need call show() for create and show the dialog.

Test: i used create dialog in other function, call the show(), but can't see the item text, same with before


i think the problem is not create() or show(), if in onCreateDialog() call create(), i can see the item, but can't see the item text.
if only call the create(), not call show() in other function, i can't see the dialog
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Thu Apr 09, 2009 2:16 pm

First: your code is still messy and nearly unreadable
Second: Where is the StackTrace?
WarrenFaith wrote:If there is an uncaught exception, than you have to find the exception in your LogCat...

Third: Try to remove the " in your array.xml
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby The_One_Neo » Fri Apr 10, 2009 2:57 am

i found the answer from the google developers

http://groups.google.com/group/android- ... 245f1c9422

Our theme for the Application was set to android:theme="@android:style/
Theme.Light" .

Setting the theme back to dark and our text now displays...

i tested the item can display.

This is an android bug ??? :shock:

i have a method can fix this problem , if we setView in the dialog ,not setItem

LayoutInflater factory = LayoutInflater.from(this);
final View View = factory.inflate(R.layout.test, null);
ListView listView = (ListView)View.findViewById(R.id.rssListView);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[] {"Ars Technica", "Slashdot", "GameKult"}));
return new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.msn)
.setTitle(R.string.delete_roster_title)
.setView(View)
.create();

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<ListView android:id="@+id/rssListView"
android:background="#7700CC00"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>

Dear Google Developers,
Please fix this if you have not already.

thank you for WarrenFaith :D
The_One_Neo
Developer
Developer
 
Posts: 28
Joined: Wed May 07, 2008 9:34 am

Postby WarrenFaith » Fri Apr 10, 2009 9:37 am

ah ok, very interessting and good to know! thank you for posting this issue here...
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests