Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclaring that a class implements OnClickListener vs. declaring it yourself?
    primarykey
    data
    text
    <p>Apologies for my title, I am having trouble properly articulating the problem.</p> <p>I have seen <code>OnCLickListener</code> implemented in two ways. The first is done by signifying that your class implements <code>OnCLickListener</code>. The second accomplishes the task by having you declare it yourself.</p> <p>Why in the first option can you simply put <code>this</code> as your <code>setOnCLickListener</code> argument, but in the second you must go through the trouble of creating the <code>OnClickListener</code> object yourself?</p> <p>The first:</p> <pre><code>public class WidgetConfig extends Activity implements OnClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.widgetconfig); Button b = (Button)findViewById(R.id.bwidgetconfig); b.setOnClickListener(this); } //onClick defined outside of the onCreate @Override public void onClick(View arg0) { // TODO Auto-generated method stub } </code></pre> <p>The Second:</p> <pre><code>public class WidgetConfig extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.widgetconfig); Button b = (Button)findViewById(R.id.bwidgetconfig); b.setOnClickListener(bListener); } private Button bListener = new OnClickListener(){ b.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { //TO-DO } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload