[Solved] method not being called java


Move your displayer(); below:

@Override
public void onClick(View v) {   

so you get:

@Override
public void onClick(View v) {
     displayer(); //Call method "displayer" when user presses button
     TextView Tv = (TextView) findViewById(R.id.TV);
     TextView Tv2 = (TextView) findViewById(R.id.Tv2);
     String date = sdf.format(calendar.getTime());
     Tv.setText("The current time is " + date);
     String str = date.charAt(0) + "" + date.charAt(1) + "" + date.charAt(3) + "" + date.charAt(4);
     Tv2.setText("So the password will be " + str);
}

But because there is no point in doing the same thing twice, you’ll only need:

@Override
public void onClick(View v) {
     displayer();         //Call method "displayer" when user presses button
}

Edit
So all in all your code would look like this:

private Button refresh;
private TextView Tv;
private TextView Tv2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    refresh = (Button)findViewById(R.id.btn1);
    Tv = (TextView)findViewById(R.id.TV);
    Tv2 = (TextView)findViewById(R.id.Tv2);

    refresh.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        displayer();            //Call method "displayer" when user presses button
    }
});

private void displayer() {
    String date = sdf.format(calendar.getTime());
    Tv.setText("The current time is "+date);
    String str=date.charAt(0)+""+date.charAt(1)+""+date.charAt(3)+""+date.charAt(4);
    Tv2.setText("So the password will be " + str);
}

PS: Check if your id’s aren’t mixed up in your XML

<TextView
        android:id="@+id/TV"   //ID is important
        //Probably more stuff
/>

and

<TextView
        android:id="@+id/Tv2"  //ID is important
        //Probably more stuff
/>

13

solved method not being called java