当我们在 viewpager 中单击图像时,我想显示网页。你能帮我解决这个问题吗?另外我想知道viewpager中是否有多个图像,那么我将如何获取它们各自的网页。
提前致谢。
**MainActivity.java**
package com.example.viewimage;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.content.Context;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
final Context context = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
ImageAdapter adapter = new ImageAdapter(this);
viewPager.setAdapter(adapter);
viewPager.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v){
// open the desired page
Intent browserIntent = new Intent("android.intent.action.VIEW",
Uri.parse("http://www.craftsvilla.com/anvi-s-classic-nawabi-earrings-studded-with-white-stones-and-emeralds.html"));
startActivity(browserIntent);
}
});
}
}