我必须在 java 警报中弹出一个对话框,通知用户如果他想删除广告必须购买付费版本的应用程序......我做了两个 java 文件..另一个叫做对话,从中回忆上面布局xml中定义的文件和其他元素...问题是如果我放置新对话框(this)会给我错误...而不是如果当前通过单击复选框运行应用程序会使应用程序崩溃。崩溃后的复选框已检查应该有...复选框不能选中。
package com.X.XX.XXX;
import android.app.AlertDialog;
import android.content.Context;
public class Dialogo {
public static final int BUY = 1000;
AlertDialog.Builder builder;
public void mostra(int Id) {
// TODO Auto-generated method stub
switch(Id)
{
case BUY:
builder.setTitle("Title");
builder.setMessage("TEXT ");
builder.setNegativeButton("CLOSE", null);
builder.setPositiveButton("BUY", null);
break;
}
builder.create().show();
}
}
package com.X.XX;
import com.X.XX.XXX.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class Settings extends PreferenceActivity{
CheckBoxPreference no_ads;
Dialogo dialogo;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.addPreferencesFromResource(R.xml.settings);
dialogo = new Dialogo();
no_ads = (CheckBoxPreference) this.findPreference("no_ads");
no_ads.setOnPreferenceClickListener(new OnPreferenceClickListener(){
@Override
public boolean onPreferenceClick(Preference preference) {
// TODO Auto-generated method stub
dialogo.mostra(Dialogo.BUY);
((CheckBoxPreference)preference).setChecked(false);
return false;
}});
}