In my android application, I am using a custom dialog. When I try to show the dialog, it causes an error. I don\'t know what I am doing wrong, and I am really confused.
<
i have created a CustomDialog. like this..
the xml is ..
and CustomDialogClass is
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
import com.example.fragmentaltdd.R;
public class CustomDialogClass extends Dialog implements
android.view.View.OnClickListener {
public Activity c;
public Dialog d;
public Button Post, Cancel,Upload;
public CustomDialogClass(Activity a)
{
super(a);
this.c = a;
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.createpost);
Post = (Button) findViewById(R.id.post_btn);
Cancel = (Button) findViewById(R.id.cancel_btn);
Upload = (Button)findViewById(R.id.upload_btn);
Post.setOnClickListener(this);
Cancel.setOnClickListener(this);
Upload.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.post_btn:
//c.finish();
Toast.makeText(c, "Post button clikced", Toast.LENGTH_LONG).show();
break;
case R.id.upload_btn:
// c.finish();
Toast.makeText(c, "Upload button clikced", Toast.LENGTH_LONG).show();
break;
case R.id.cancel_btn:
dismiss();
break;
default:
break;
}
dismiss();
}
}
And call it like this
CustomDialogClass cdd = new CustomDialogClass(getActivity());//while calling from fragment
CustomDialogClass cdd = new CustomDialogClass(YourActivity.this);//while calling from Activity
cdd.show();