如何使我的微调器目标链接到网站? [英] How do I make so my spinner target links to a website?

查看:24
本文介绍了如何使我的微调器目标链接到网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我是几个小时前刚刚开始的 Android 开发新手.我需要申请学校项目,而且需要尽快完成.

Hey, I'm really new with android development just started a few hours ago. I need to make a application for a school project and it needs to be done soon.

到目前为止,我已经制作了一个带有一些可供选择的旋转器.但这是我的问题.当我点击我的微调器中列出的目标之一以链接到网页时,我该如何做到这一点.

So far have I made a spinner with some alternatives to choose from. But here is my problem. How do I make so when I click on one of the targets listed in my spinner so it links to a webpage.

我不知道如何使用AdapterView.OnItemSelectedListener".或者这里是否有必要.

I don't know how to use "AdapterView.OnItemSelectedListener." or if it is necessary here or not.

我会非常感谢一些建议.谢谢头

I would be very thankful for some advices. thanks a head

推荐答案

您可以尝试将 onItemSelectedListener 设置为您的微调器:

You can try setting the onItemSelectedListener to your spinner:

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource( this, R.array.planets_array, android.R.layout.simple_spinner_item);   
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);   
spinner.setAdapter(adapter);

spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

  @Override
  public void onItemSelected(AdapterView<?> arg0, View arg1,
          int arg2, long arg3) {
      startActivity(new Intent(Intent.ACTION_VIEW,
             Uri.parse("http://yoururl.com")));
  }

  @Override
  public void onNothingSelected(AdapterView<?> arg0) {}

});

这将使用您的网址打开浏览器.

This will open the browser with your url.

这篇关于如何使我的微调器目标链接到网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆