我正在弹出框中列出用户的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();
}
}
所有日志记录正确的事情......就在警报显示时没有列表。有什么想法吗?
答案 0 :(得分:10)
您可以使用setMessage()
或setAdapter()
。它们是相互排斥的。如果同时使用两者,则消息将获胜。解决方案是删除setMessage()
并改为使用setTitle()
。