开发者

How do I make so my spinner target links to a website?

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 c开发者_C百科hoose 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.

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


You can try setting the onItemSelectedListener to your spinner:

EDIT:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜