2012-02-07 3 views
0

私はこれについて前に投稿しましたが、ivは運がなかった。これは私が今のところ持っているコードです。私は何を探しているのですか?私のボタンは私のダイアログで、単に元の 画面に戻る(または閉じる)。私はアンドロイドのバックボタンについて読んでいて、ちょうど私の頭の上に行く。あなたが正しくあなたのボタンを接続していないダイアログボタンが機能しない

java.code

import my.dlog.R; 
import android.app.Activity; 
import android.app.Dialog; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.view.View.OnClickListener; 

public class DlogActivity extends Activity { 
/** Called when the activity is first created. */ 
Dialog dialog; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
dialog = new Dialog(this); 
dialog.setContentView(R.layout.main2); 
dialog.setTitle("This is my custom dialog box"); 
dialog.setCancelable(true); 
Button b=(Button)findViewById(R.id.button1); 

b.setOnClickListener(new OnClickListener() { 
    public void onBackPressed() { 
    Intent intent = new Intent(DlogActivity.this, DlogActivity.class); 
    startActivity(intent); 
    finish(); 
    } 

    public void onClick(View v) { 
    dialog.show(); 
    } 
}); 

} 
} 

xml.code

<Button 
    android:id="@+id/btn2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom" 
    android:text="Button" 
    android:onClick="DlogActivity"/> 




    <ImageView 
    android:layout_width="236dp" 
    android:layout_height="220dp" 
    android:layout_marginRight="100dp" android:background="@drawable/carsee"/> 


    <RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

答えて

0

コードが完全にわかりにくいです。私はあなたが活動と対話の違いについて混乱するかもしれないと思う。あなたがしようとしているのは、あなたの活動の上にダイアログを表示してから、ダイアログが閉じられたときにそのアクティビティに戻る場合は、dialog.dismiss()が必要です。 Read this

他の目的を達成しようとしている場合は、説明してください。

+0

コメントありがとうございます。私は解決策を見つけた – ravon30

0

。あなたは、Javaの

Button b=(Button)findViewById(R.id.button1); 

にボタン1のIDを探しますが、XMLには、これらのIDの一致を確認してくださいボタンをBTN2

<Button 
    android:id="@+id/btn2" 
    android:layout_width="wrap_content" 
    . 
    android:onClick="DlogActivity"/> 

のIDを割り当てます。

+0

デイログの画面を閉じようとしています。私はちょっと失ったと思う。しかし、私はそれが何の後のように聞こえるalertdialogでagianを開始すると思う。 button.textviewとimageview.thankあなたのコメントのために – ravon30

関連する問題