setup an event listener
public class NumbersClickListener implements OnClickListener { @Override public void onClick(View view) { Toast.makeText(view.getContext(), "Open the list of numbers", Toast.LENGTH_SHORT).show();} } NumbersClickListener clickListener = new NumbersClickListener(); buttonView.setOnClickListener(clickListener); TextView priceTextView = new TextView()
package com.example.android.miwok; import android.view.View; import android.widget.Toast; public class NumbersClickListener implements View.OnClickListener { @Override public void onClick(View view) { Toast.makeText(view.getContext(), "Open the list of numbers", Toast.LENGTH_SHORT).show(); } }
MainActivity.java
package com.example.android.miwok; import android.conent.Intent; import android.support.v7.app.AppCompactActivity; import android.os.Bundle; import android.view.View; public class MainActivity extends AppCompactActivity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); NumbersClickListener clickListener = new NumbersClickListener(); // Find the View that shows the numbers category TextView numbers = (TextView)findViewById(R.id.numbers); //Set a clickListener on that View numbers.setOnClickListener(click.Listener); } }