import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
public static final String PREFS_NAME = "MyPrefsFile1";
public CheckBox dontShowAgain;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CheckBox dontShowAgain = new CheckBox(this);
TextView textViewTerms = new TextView(this);
textViewTerms.setText("Terms & Conditions ");
TextView textView = new TextView(this);
textView.setText(Html.fromHtml("<u>Details</u>"));
textView.setTextColor(Color.BLUE);
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "clicked",
Toast.LENGTH_LONG).show();
}
});
LinearLayout checkBoxLayout = new LinearLayout(this);
checkBoxLayout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
checkBoxLayout.addView(dontShowAgain);
checkBoxLayout.addView(textViewTerms);
checkBoxLayout.addView(textView);
AlertDialog.Builder altDialog = new AlertDialog.Builder(this);
altDialog.setCancelable(false);
altDialog.setView(checkBoxLayout);
altDialog.setMessage("Do not Show Again");
altDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
String checkBoxResult = "NOT checked";
if (dontShowAgain.isChecked())
checkBoxResult = "checked";
SharedPreferences settings = getSharedPreferences(
PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
// Commit the edits!
editor.commit();
return;
}
});
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage", "NOT checked");
if (skipMessage != "checked") {
altDialog.show();
}
}
}
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
public static final String PREFS_NAME = "MyPrefsFile1";
public CheckBox dontShowAgain;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final CheckBox dontShowAgain = new CheckBox(this);
TextView textViewTerms = new TextView(this);
textViewTerms.setText("Terms & Conditions ");
TextView textView = new TextView(this);
textView.setText(Html.fromHtml("<u>Details</u>"));
textView.setTextColor(Color.BLUE);
textView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "clicked",
Toast.LENGTH_LONG).show();
}
});
LinearLayout checkBoxLayout = new LinearLayout(this);
checkBoxLayout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
checkBoxLayout.addView(dontShowAgain);
checkBoxLayout.addView(textViewTerms);
checkBoxLayout.addView(textView);
AlertDialog.Builder altDialog = new AlertDialog.Builder(this);
altDialog.setCancelable(false);
altDialog.setView(checkBoxLayout);
altDialog.setMessage("Do not Show Again");
altDialog.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
String checkBoxResult = "NOT checked";
if (dontShowAgain.isChecked())
checkBoxResult = "checked";
SharedPreferences settings = getSharedPreferences(
PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("skipMessage", checkBoxResult);
// Commit the edits!
editor.commit();
return;
}
});
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String skipMessage = settings.getString("skipMessage", "NOT checked");
if (skipMessage != "checked") {
altDialog.show();
}
}
}
No comments:
Post a Comment