Hi I'm developing an application that will require a Dialog Window, using a 
listview to select an item from this list.

The problem is I have two possibilities to implement, the easier (I think) is 
using the AlertDialog.Builder, but the problem is here is my code, when the 
button is pressed:

Context mContext = getApplicationContext();

LayoutInflater inflater = (LayoutInflater) 
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);

View _dialog_layout = inflater.inflate(R.layout.source, (ViewGroup) 
findViewById(R.layout.shelf));

ListView _mslv = (ListView) _dialog_layout.findViewById(R.id.list);

_ms_manager = new MyCustomManager();
_ms_adapter = new MyCustomSourceAdapter(mContext, R.layout.row, new 
ArrayList<MyCustomSourceItem>());

List< MyCustomSourceItem > _msList = _ms_manager.getSources();

for(MyCustomSourceItem _msItem : _msList) {
        _ms_adapter.add(_msItem);
}
_mslv.setAdapter(_ms_adapter);

builder = new AlertDialog.Builder(mContext);

builder.setView(_dialog_layout);

alertDialog = builder.create();

alertDialog.show();

When I try it the debug presents the following on LogCat:

01-05 11:29:46.880: WARN/WindowManager(68): Attempted to add window with 
non-application token WindowToken{409ebaa0 token=null}.  Aborting.
01-05 11:31:19.151: ERROR/AndroidRuntime(970): FATAL EXCEPTION: main
01-05 11:31:19.151: ERROR/AndroidRuntime(970): 
android.view.WindowManager$BadTokenException: Unable to add window -- token 
null is not for an application
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.view.ViewRoot.setView(ViewRoot.java:531)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.app.Dialog.show(Dialog.java:241)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
com.underdev.android.shelf.Shelf$1.onClick(Shelf.java:178)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.view.View.performClick(View.java:2485)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.view.View$PerformClick.run(View.java:9080)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.os.Handler.handleCallback(Handler.java:587)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.os.Handler.dispatchMessage(Handler.java:92)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.os.Looper.loop(Looper.java:123)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
android.app.ActivityThread.main(ActivityThread.java:3647)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
java.lang.reflect.Method.invokeNative(Native Method)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
java.lang.reflect.Method.invoke(Method.java:507)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-05 11:31:19.151: ERROR/AndroidRuntime(970):     at 
dalvik.system.NativeStart.main(Native Method)


So the question is why and how to solve this problem ?


The  second scenario is creating a new Activity  and I already did that and it 
worked:

Intent _i = new Intent(mContext, SourceDialog.class);
startActivity(_i);
startSubActivity(_i, 0);

The problem is how to obtain which element in the listview was selected ? How 
to pass this information from one Activity to another ?

Regards,

 Vitorio.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to