Why OnClickListener is not called by clicking?

advertisements

This is my code for the BASE class, i am inheriting this class to another child class. And from that class i am calling this function ActiveSMSPackage(). My code is perfect which has not kind of any error but yet the method is not called. Can you guys tell me where i am doing wrong?

public class PrepaidSMSBase extends Activity {

private String smsNumber = "";
private String smsPackageName;
private String smsPrice;
private String smsTitle;
private String smsText;

public PrepaidSMSBase(){}

public void setSmsPackageInformation(String smsTitle, String smsPackageName, String smsPrice, String smsNumber, String smsText)
{
    this.smsTitle = smsTitle;
    this.smsPackageName = smsPackageName;
    this.smsPrice = smsPrice;
    this.smsNumber = smsNumber;
    this.smsText = smsText;

}

public void activeSMSPackage()
{
    try
    {AlertDialog.Builder builder = new AlertDialog.Builder(PrepaidSMSBase.this);
        builder.setTitle(smsTitle);
        builder.setMessage("Are you sure you want to active" + PrepaidSMSBase.this.smsPackageName + "in RS: " +
                PrepaidSMSBase.this.smsPrice);
        builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Uri uri = Uri.parse("smsto:" + smsNumber);
                Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
                intent.putExtra("sms_body", smsText);
                startActivity(intent);
                Toast.makeText(getApplicationContext(), "Please click send button to activate desire Package", Toast.LENGTH_LONG).show();
            }
        });
    }catch (ActivityNotFoundException e){
        e.printStackTrace();
    }
}

Code of Child class is:

public class SMSCheckClass extends PrepaidSMSBase implements View.OnClickListener{

Button checkButton;

public SMSCheckClass(){
    setSmsPackageInformation("Test 1","Some Thing","50","660","Sub");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.checksms);
    checkButton = (Button)findViewById(R.id.chkBtn);
    checkButton.setOnClickListener(this);
}

@Override
public void onClick(View v)
{
    activeSMSPackage();
}


Use this code

        {AlertDialog.Builder builder = new AlertDialog.Builder(PrepaidSMSBase.this);
        builder.setTitle(smsTitle);
        builder.setMessage("Are you sure you want to active" + PrepaidSMSBase.this.smsPackageName + "in RS: " +
                PrepaidSMSBase.this.smsPrice);
        builder.setPositiveButton("Activate", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Uri uri = Uri.parse("smsto:" + smsNumber);
                Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
                intent.putExtra("sms_body", smsText);
                startActivity(intent);
                Toast.makeText(getApplicationContext(), "Please click send button to activate " + PrepaidSMSBase.this.smsPackageName, Toast.LENGTH_LONG).show();
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.show();

you just need to add builder.show() in the end of AlertDialog because your function is written inside of AlertDialog and that show() method is used to show AlertDialog