我有一个按钮,你需要一个简短的描述示例图片,但我想要做的就是长时间点击,然后让它把用户带到一个网站更多信息。我怎样才能实现可在我的应用程序中的longclickable
这里是我为我的按钮(正常)
<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"/>
代码和我的Java是这个
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);
如何将longclickable添加到该带我去一个网站吗? 任何人都可以请帮忙吗?
我已经加入了,但现在看来要带我到这个网站(longclicking后),而不是像(正常的onclick后)我的继承人代码:
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);
得到一条黄线在“公共无效的onClick(查看图){”
你不能像这样组合一个OnClickListener和OnLongClickListener,我更新了我的答案。 – Sam