我在ListView上方添加了一个图像滑块(Daimajia's AndroidImageSlider库)。图像滑块成功从Drawable加载图像。我想要做的是:当点击特定图像时,它会将我重定向到网站网址。有没有可行的方法呢?我试过了#34;如果(name == image_name)然后是Intent",但它不起作用。请帮帮我。感谢。
public class HomeFragment extends Fragment implements BaseSliderView.OnSliderClickListener {
public static final String TAG_CATEGORY = "category";
Button lifestyle, men, women, books, cars, furnitures, photography, music;
String life;
private SliderLayout mSlider;
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home,container,false);
lifestyle = (Button) rootView.findViewById(R.id.button_lifestyle);
men = (Button) rootView.findViewById(R.id.button_men);
women = (Button) rootView.findViewById(R.id.button_women);
books = (Button) rootView.findViewById(R.id.button_books);
cars = (Button) rootView.findViewById(R.id.button_cars);
furnitures = (Button) rootView.findViewById(R.id.button_furnitures);
photography = (Button) rootView.findViewById(R.id.button_photography);
music = (Button) rootView.findViewById(R.id.button_music);
mSlider = (SliderLayout)rootView.findViewById(R.id.slider);
//HashMap<String,String> url_maps = new HashMap<String, String>();
//url_maps.put("Car", "http://gemini888.tk/GPFileUpload/uploads/car.jpg");
//url_maps.put("Camera", "http://gemini888.tk/GPFileUpload/uploads/camera.jpg");
//url_maps.put("Men", "http://gemini888.tk/GPFileUpload/uploads/men.jpg");
//url_maps.put("Women", "http://gemini888.tk/GPFileUpload/uploads/women.jpg");
HashMap<String,Integer> file_maps = new HashMap<String, Integer>();
file_maps.put("Tourist Guide",R.drawable.tourist);
file_maps.put("Local Food",R.drawable.food);
file_maps.put("Penang Art",R.drawable.penang);
file_maps.put("Puchong Food", R.drawable.puchong);
Drawable resTou = this.getResources().getDrawable(R.drawable.tourist);
Drawable resFood = this.getResources().getDrawable(R.drawable.food);
Drawable resPen = this.getResources().getDrawable(R.drawable.penang);
Drawable resPuc = this.getResources().getDrawable(R.drawable.puchong);
for(String name : file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(getActivity());
// initialize a SliderLayout
textSliderView
.description(name)
.image(file_maps.get(name))
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);
//add your extra information
textSliderView.getBundle().putString("extra",name);
mSlider.addSlider(textSliderView);
}
mSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
mSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
mSlider.setCustomAnimation(new DescriptionAnimation());
mSlider.setDuration(4000);
lifestyle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent a = new Intent(getActivity(), Category_product.class);
startActivity(a);
}
});
men.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Men_product.class);
startActivity(b);
}
});
women.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Women_product.class);
startActivity(b);
}
});
books.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Books_product.class);
startActivity(b);
}
});
cars.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Cars_product.class);
startActivity(b);
}
});
furnitures.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Furnitures_product.class);
startActivity(b);
}
});
photography.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Photography_product.class);
startActivity(b);
}
});
music.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View rootView) {
Intent b = new Intent(getActivity(), Music_product.class);
startActivity(b);
}
});
return rootView;
}
@Override
public void onSliderClick(BaseSliderView slider) {
// TODO Auto-generated method stub
//Intent touristIntent = new Intent("android.intent.action.VIEW",Uri.parse("http://m.mygp.la/mr/m.aspx?m=MelakaTouristGuide"));
//Intent touristIntent = new Intent(getActivity(),AllProductActivity.class);
//startActivity(touristIntent);
}
}
答案 0 :(得分:1)
尝试使用开关(位置){ 情况1 : 的意图强>
}
答案 1 :(得分:0)
我没有声明发表评论,所以把它作为答案,看看是否有帮助: 1.我想你想比较String,所以它应该是“if(name.equals(image_name))”。 “if(name == image_name)”正在检查同一个对象。