So I have done some research, and after defining you button as an object by the code
private Button buttonname;
buttonname = (Button) findViewById(R.id.butto
package com.mani.helloworldapplication;
import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements View.OnClickListener {
//Declaration
TextView tvName;
Button btnShow;
@Override
protected void onCreate(Bundle savedInstanceState) {
//Empty Window
super.onCreate(savedInstanceState);
//Load XML File
setContentView(R.layout.activity_main);
//Intilization
tvName = (TextView) findViewById(R.id.tvName);
btnShow = (Button) findViewById(R.id.btnShow);
btnShow.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
String name = tvName.getText().toString();
Toast.makeText(MainActivity.this,name,Toast.LENGTH_SHORT).show();
}
}