EF's Blog

Posts Tagged ‘edittext

I create this method

public static boolean isNotEmptyValidator (String strValue,int intMinLength)
{
if(strValue.length() < intMinLength)
return false;
else
return true;
}

and use this to use it:

EditText etEmail = (EditText)findViewById(R.id.etContactEmail);
EditText etNama= (EditText)findViewById(R.id.etContactNama);

String strErrorMsg = “”, strEmailContent =””;
boolean boolValid = true;

if(boolValid == true)
{
if(validator.isNotEmptyValidator(etEmail.getText().toString(), 11))
{
strErrorMsg += “Email tidak boleh kosong dan harus memiliki format email yang benar. (contoh : cs@sinarmasmsiglife.co.id).\n”;
boolValid = false;
if(validator.emailValidator(etEmail.getText().toString()) == false)
{
strErrorMsg = “Format Email tidak benar. (contoh format email yang benar: cs@sinarmasmsiglife.co.id)”;
}
}
if(validator.isNotEmptyValidator(etNama.getText().toString(), 3))
{
strErrorMsg += “Nama tidak boleh kosong dan minimal 3 karakter.\n”;
boolValid = false;
}

Advertisements
Button   mButton;
EditText mEdit;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mButton = (Button)findViewById(R.id.button);
    mEdit   = (EditText)findViewById(R.id.edittext);

    mButton.setOnClickListener(
        new View.OnClickListener()
        {
            public void onClick(View view)
            {
                Log.v("EditText", mEdit.getText().toString());
            }
        });

Resizing a textfield using XML in Android is easy. Code snippet below.


< EditText
android:textSize="12px"
android:editable="true"
android:autoText="true"
android:maxLength="50"
android:singleLine="True"
android:layout_width="200px"
android:layout_height="20px"
/>


Size values are in float values and determined by px (pixels), sp (scaled pixels based on preferred font size), db (density-independent pixels), in (inches) and mm (millimeters).


EF’s Blog

I'm just ordinary people who lived in an extra-ordinary world.

EF's Blog Stats

  • 138,553 hits
October 2017
M T W T F S S
« Jul    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Archives