Tag Archives: Button

How to call a click on a button Programatically?

By | March 10, 2018

The click on a button or View is usually called when the user clicks on it. But how can we call it programatically. Here is a simple example [java] Button btnClick = findViewById(R.id.btnClick); LinearLayout mLayout = findViewById(R.id.mLayout); // perform click on button btnClick.performClick(); // perform click on Linear Layout mLayout.performClick(); [/java] yes “performClick()”, this is how to call… Read More »

DataBinding in Android using Observable Collections

By | January 30, 2017

As I shown in the previous post where we used BaseObservable and ObservableField to update UI when binding object is changed, this post will show you another simple way to achieve this. Do Check my previous posts for better understanding of DataBinding and methods used in DataBinding. http://www.coderzheaven.com/2017/01/15/simple-databinding-in-android-example/ http://www.coderzheaven.com/2017/01/20/data-binding-in-android-using-observables/ http://www.coderzheaven.com/2017/01/25/data-binding-in-android-using-observablefield-to-update-ui-automatically/ Here is another way to do it. In… Read More »

How to show error in an EditText using setError() in Android?

By | September 18, 2012

We will go straight to the code. [java] package com.coderzheaven.seterror; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn =(Button)findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { EditText edittext =(EditText)findViewById(R.id.editText1); if(edittext.getText().length()==0){ edittext.setError("Field cannot be left blank."); }… Read More »

How to make a Button appear like a TextView in Android?

By | August 14, 2012

Hello all….. This is a simple trick where we can make the Button appear like a TextView in Android. This is done by setting the background of Button to null like this. b.setBackgroundDrawable(null); This is the xml that contains the button. [xml] <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" android:textColor="#FFF" android:id="@+id/but" />… Read More »

Global variables in ANDROID……

By | May 17, 2011

Hi all……. In today’s exampl e I will show you how to deal with global variables in ANDROID. You know global variables are those variables that you can access across any variables. It’s value becomes changed when you change it in any of the classes in your project. These types of variables act as like cookies in a… Read More »

How to use Global variables in ANDROID?

By | May 17, 2011

Hi all……. In today’s exampl e I will show you how to deal with global variables in ANDROID. You know global variables are those variables that you can access across any variables. It’s value becomes changed when you change it in any of the classes in your project. These types of variables act as like cookies in a… Read More »

How to send email from and ANDROID Application programatically?

By | May 16, 2011

Hello all…….. In today’s post I will show you send mail from an android application progrmatically.. Let’s go to the code fast…… This is the code in the mail java file…. [java] package com.coderzheaven; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class sendMailDemo extends Activity { Button send;… Read More »

Email validation in ANDROID.

By | May 1, 2011

This is a simple example showing email validation in ANDROID. This example uses regex for email validation. Create a button and an edittext in your main.xml file and try this code. [java] package com.coderzheaven; import java.util.regex.Pattern; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class EmailValidationDemo extends… Read More »