1

我正在一个弹出框中列出用户的 tumblr 博客。所有这些都发生在一个处理程序中。这是代码:

private class PicHandler extends Handler{
    Context c;
    String name;
    JumblrClient client;
    public PicHandler(Context context, String n, JumblrClient cl){
        c=context;
        name = n;
        client = cl;
    }
    public void handleMessage(Message msg)
    {
        final String[] cs = preferences.getString("allBlogs", "").split(",");
        for (String s : cs){
            Log.d("DrawLog", s); //logs the blogs correctly
        }

        ListAdapter adapter = new ArrayAdapter<String>(
                getApplicationContext(), android.R.layout.simple_selectable_list_item, cs);
        Log.d("DrawLog", (String) adapter.getItem(0)); //logs the first blog correctlys
        new AlertDialog.Builder(c)
        .setTitle("Choose blog")
        .setMessage("Choose the blog to publish the .gif")
        .setAdapter(adapter, new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int which) {
                        String root_sd = Environment.getExternalStorageDirectory().toString();
                        File file = new File( root_sd + "/Flippy/" + name) ;  
                        if(file.exists()){
                            Log.d("DrawLog", "file exists"); //file exists
                            Log.d("DrawLog", file.getPath());
                        }

                        PhotoPost post;
                        try {
                            post = client.newPost(cs[which], PhotoPost.class); 
                            //Photo p = new Photo();

                            post.setData(file);
                            Log.d("DrawLog" , post.toString()+"");

                            post.save();
                        } catch (IllegalAccessException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (InstantiationException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        catch(NullPointerException e){
                            Log.d("DrawLog", "null pointer wtf");
                        }

                   }
                }).create().show();         
        }
}

所有日志都记录了正确的事情......只是当警报显示时没有列表。任何想法为什么?

4

1 回答 1

14

您可以使用setMessage()setAdapter()。它们是相互排斥的。如果您同时使用两者,则消息获胜。一个解决方案是删除setMessage()setTitle()改用。

于 2013-08-19T21:59:16.760 回答