Android Java Occur a method event -


hello want methods work instantly when user enters application. have onclick event in xml activates methods(this works).

the xml:

            <textview             android:id="@+id/cd_start"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:fontfamily="sans-serif-light"             android:gravity="center"             android:paddingbottom="0dp"             android:text="time"             android:textcolor="#000"             android:textsize="21sp"             android:onclick="dateend"/> 

and main activity.java

string datestopkukuk = "21 dec 2015";  private void displaydateend(string etime) {     textview pricetextview = (textview) findviewbyid(r.id.cd_start);     pricetextview.settext(etime); }  public void dateend(view v) {     displaydateend(datestopkukuk); } 

edit: added comments explain code.

try this:

import android.app.activity; import android.view.view; import android.widget.textview; public class mainactivity extends activity implements view.onclicklistener  {      // onclick method called when 1 of view clicked. (you must use setonclicklistener on view inform system call this)     @override     public void onclick(view v)     {         // check if clicked view cd_start         if(v.getid() == r.id.cd_start)         {              // true cd_start clicked              displaydateend(datestopkukuk);         }     }      @override     protected void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate); // required!!! when don't add app crash.         setcontentview(r.layout.activity_main); // sets activity_main layout (if use different name of layout replace activity_name layout name)         findviewbyid(r.id.cd_start).setonclicklistener(this); // finds view cd_start id , sets click listener. when view clicked system calls onclick method.         // , code want when activity creating.     }      string datestopkukuk = "21 dec 2015";      private void displaydateend(string etime) {         textview pricetextview = (textview) findviewbyid(r.id.cd_start);         pricetextview.settext(etime);     }      /* don't need dateend method */ } 

xml:

        <textview             android:id="@+id/cd_start"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:fontfamily="sans-serif-light"             android:gravity="center"             android:paddingbottom="0dp"             android:text="time"             android:textcolor="#000"             android:textsize="21sp"             /> <!-- don't need android:onclick --> 

in activity.

i hope helped you.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -