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

后端 未结 1 1586
傲寒
傲寒 2021-01-16 11:56

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 ha

1条回答
  •  梦毁少年i
    2021-01-16 12:10

    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 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 讨论(0)
提交回复
热议问题