java - How to assign a class to execute onClick? -


fellow coders!

so i'm pretty fresh on coding, , migrated c# java! everythings works out way want: i've coded fancy looking circular buttons, , created following class:

    package com.example.haavard.gosecure;  /**  * created haavardkleven on 08.08.2016.  */  import java.util.random;   public class passwordgenerator {     public static void main(string[] args) {         int length = 16; //adjust lenght of generated password here         system.out.println(generatepswd(length));     }      static char[] generatepswd(int len) {         system.out.println("your secure password is:");         string charcaps = "abcdefghijklmnopqrstuvwxyz";         string chars = "absdefghijklmnopqrstuvwxyz";         string numbers = "1234567890";         string symbols = "!@#£$%^*_=+-/.?<>)";          string passsymbols = charcaps + chars + numbers + symbols;         random rnd = new random();          char[] password = new char[len];         int index = 0;         (int = 0; < len; i++)         {             password[i] = passsymbols.charat(rnd.nextint(passsymbols.length()));         }         return password;     } } 

now, since memroy of coding , knowledge of "android studio" isn't high, have problem:

how assign class method onclick listener in mainactivity? want application run class, , print result textfield setup on layout page.

i know, probaly there topic this, can not seem find answer..

in activity in layout-xml, add android:onclick="yourmethod" button.

in activity itself, create method this:

public void yourmethod(view view){  } 

the onclick automatically access method.

in method, can access class passwordgenerator , call static method. final code this:

public void yourmethod(view view){     char[] pw = passwordgenerator.generatepswd(42); } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -