samedi 21 avril 2018

Button to link in java with if else statement

I am not sure. What I am doing wrong. I am trying to make a button that direct you to google when it pressed with (if, else statement) I am trying to make it work since yesterday but when I press the Button it just do the else statement ( try again) I don't know what in wrong with the code

This is my code

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class files extends Activity {

    private EditText etfile;
    private Button btnfile;
    private Intent in = new Intent();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_files);
        initialize();
        initializeLogic();
    }

    private void initializeLogic() {
    }


    private void initialize() {
    btnfile = (Button) findViewById(R.id.btnfile);
    etfile = (EditText) findViewById(R.id.etfile);

    btnfile.setOnClickListener(new View.OnClickListener(){
        @Override
    public void onClick(View _v) {
        if(etfile.equals("google"))
        {
            in.setAction(Intent.ACTION_VIEW);
            in.setData(Uri.parse("http:google.com"));
            startActivity(in);
        }
         else {
            etfile.setText("Try Again");
        }
    }
});
}

}

Aucun commentaire:

Enregistrer un commentaire