Implementing Code Behind Clickable TextViews
I just started working with clickable TextViews in Eclipse. The line in the code below: t2.setOnClickListener(this); seems to be having a problem. I have tried a variety of met
Solution 1:
TextView t2 = (TextView) findViewById(R.id.textView);
t2.setOnClickListener(new View.setOnClickListener() {
public void onClick(View view) {
mp.start();
}
});
OR
TextView t2 = (TextView) findViewById(R.id.textView);
t2.setOnClickListener(this);
@Override
public void onClick(View v) {
if(v == t2){
// logic
}
}
This is the right way of setting on click listeners.
Solution 2:
In your code above, you are setting the onClickListener twice, which is unnecessary. The second time you set it will override the first, and the result of the click should be the execution of mp.start();
Can you describe in more detail what your problem is? What is or isn't happening when you run your app?
Post a Comment for "Implementing Code Behind Clickable TextViews"