2012-04-01 63 views
0

这是我的麻烦的对话java文件。这是非常相似的其他对话框文件,我工作得很好。问题是当另一个进度对话框完成时,这个对话框会被调用。另一个关闭,但这个新的不会打开(但代码运行),我不明白为什么。对话框不会出现在android中,为什么?

public class Response extends Dialog implements OnClickListener { 

    Button cpandclose; 
    EditText response; 
    Context context; 

    //Skapar dialog med About xml filen 
    public Response(Context context, String url) { 
     super(context); 
     /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */ 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     /** Design the dialog in main.xml file */ 
     setContentView(R.layout.response); 

     cpandclose = (Button) findViewById(R.id.cpandclose); 
     cpandclose.setOnClickListener(this); 
     response = (EditText) findViewById(R.id.resposeurl); 
     response.setText("http://xxx.com/i/" + url); 
     this.context = context; 
     Log.d("Response Window: ", "running.."); 
    } 

    public void onClick(View v) { 
     if (v == cpandclose) { 
      ClipboardManager ClipMan = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 
      ClipMan.setText(response.getText()); 
      dismiss(); 
     } 
    } 
} 

xml-file对于不会显示该对话框:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/responsetxt" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Response:" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <EditText 
     android:id="@+id/resposeurl" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <requestFocus /> 
    </EditText> 

    <Button 
     android:id="@+id/cpandclose" 
     android:layout_width="225dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:text="Copy and Close" /> 

</LinearLayout> 

在后台上传一些数据,当它完成其应用的数据返回到字符串的应用功能:

camera.responseFromServer(serverResponse); 

调用当前摄像头对象中的方法responseFromServer,并调用它的函数如下:

public void responseFromServer(String url) { 
Looper.prepare(); 
Response response = new Response(this, url); 
Log.d("response: ", url); 
response.show(); 
} 

这运行程序,但我看不到任何对话框显示。怎么可能?这可能是一个简单的解决方案,但感觉就像我尝试了一切!

感谢您的建议和更好的智慧。

回答

3

因为不应在responseFromServer()中创建对话框,而应在onCreateDialog()中创建对话框。

+0

非常感谢。 :) – Ms01 2012-04-01 19:54:40

+0

出于好奇,你为什么不接受这个答案?最好的祝福。 – pouzzler 2012-04-12 12:07:18

+0

因为它没有工作。我遵循从android开发网站的指导方针,并且当我从我的服务器收到数据时,对话框不会显示。如果你想研究它,我可以在家时发布更多细节。 :) – Ms01 2012-04-16 12:11:42

相关问题