I have post about this before but iv had no luck. this is my code that i have at the moment. what i am looking for is. My button on my dialog to simply go back (or close) to the origanl
screen. i have been reading about the back button in android and it just go’s over my head.
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" >
Your code is totally confusing to me. I suspect that you might be confused about the difference between an activity and a dialog. If all you are trying to do is show a dialog on top of your activity, and then return to that activity when the dialog is dismissed, you need dialog.dismiss(). Read this
If you are trying to achieve something else, please explain.