AlertDialog上的android-setAdapter无法正常工作

时间:2013-08-19 20:14:08

标签: java android handler android-alertdialog listadapter

我正在弹出框中列出用户的tumblr博客。所有这些都发生在Handler中。这是代码:

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();         
        }
}

所有日志记录正确的事情......就在警报显示时没有列表。有什么想法吗?

1 个答案:

答案 0 :(得分:10)

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