Issue
I have a button wich takes you to a sample picture with a short description, but what i would like to do is to long click and then let it take the user to a website for more information.
here is my code for my button (normal)
<Button
android:id="@+id/samplea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="20dp"
android:background="@drawable/samplea_button"
android:longClickable="true"/>
and my java is this
Button next = (Button) findViewById(R.id.samplea);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplea_draw);
How do I add the longclickable to this to take me to a website? Can anyone please help?
I have added it, but now it seems to take me to the this website (after longclicking), but not to the image (after normal onclick) heres my code:
next1.setOnLongClickListener(new OnLongClickListener() {
public boolean onLongClick(View v) {
// Launch your web intent
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/a/13298207/1267661"));
startActivity(intent);
return true;
}
public void onClick(View view) {
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplea_draw);
get a yellow line under "public void onClick(View view) {"
Solution
Updated
Implement an OnLongClickListener much like your OnClickListener, but it needs to be separate. Try this:
Button next = (Button) findViewById(R.id.samplea);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
// You can turn this into a class variable
final ImageView imageView = (ImageView) findViewById(R.id.iM2);
imageView.setImageResource(R.drawable.samplea_draw);
}
)};
next.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// Launch your web intent
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://stackoverflow.com/a/13298207/1267661"));
startActivity(intent);
return true;
}
});
Answered By - Sam
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.