Skip to content

Instantly share code, notes, and snippets.

@a-v-ebrahimi
a-v-ebrahimi / ShowAlert
Created January 29, 2012 17:33
Show Alert in Android
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Reset...");
alertDialog.setMessage("Are you sure?");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
@a-v-ebrahimi
a-v-ebrahimi / ShowAlert2Buttons
Last active January 25, 2019 15:50
Show alert with one, two or more buttons (android)
public void onClick(View view) {
if(view == this.alertBtn){
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Alert 1");
alertDialog.setMessage("This is an alert");
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
}else if(view == this.alert2Btn){
@a-v-ebrahimi
a-v-ebrahimi / andActivity
Created February 2, 2012 12:00
android activity class
import android.app.Activity;
import android.os.Bundle;
public class actSpecial extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_);
registerEvents();
@a-v-ebrahimi
a-v-ebrahimi / showActivity
Created February 6, 2012 19:36
android Show Activity
Intent intent = new Intent(FirstActivity.this, OrderScreen.class);
startActivity(intent);
@a-v-ebrahimi
a-v-ebrahimi / getdatafromactivitybundle
Last active October 1, 2015 11:48
get data from Activity Bundle
Bundle bundle = this.getIntent().getExtras();
if (bundle!=null && bundle.containsKey("input"))
{
String txt=bundle.getString("input");
}
@a-v-ebrahimi
a-v-ebrahimi / sendemail
Created March 10, 2012 02:50
android : Send email
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL,new String[] { "[email protected]" });
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of the mail");
intent.putExtra(Intent.EXTRA_TEXT, "body of the mail");
startActivity(Intent.createChooser(intent, "Title of the chooser dialog"));
@a-v-ebrahimi
a-v-ebrahimi / custom_spinner
Last active December 14, 2019 13:31
Android: Spinner with custom adapter and layout
String[] ss = getResources().getStringArray(R.array.authors_array);
final String[] items = { ss[1],ss[2],ss[3],ss[4],ss[5],ss[6],ss[7],ss[8],ss[0] };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("نتيجه جستجو");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row_for_spinner, R.id.lblText, items);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@a-v-ebrahimi
a-v-ebrahimi / AddToManifest
Created April 7, 2012 07:11
Remove Activity Title bar
<application android:theme="@android:style/Theme.NoTitleBar">
@a-v-ebrahimi
a-v-ebrahimi / AsyncTask
Created April 8, 2012 04:54
Android AsyncTask
.
.
.
new DownloadFilesTask().execute(url1, url2, url3);
.
.
.
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
@a-v-ebrahimi
a-v-ebrahimi / changetablebackground
Created April 9, 2012 13:05
iPhone : Change background of UITableView to image
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BackgroundPattern.png"]];