我该如何组合 我创建的3个微调器的选项,并将其链接到按钮? 这是我的代码......
package com.example.nikhiljoshi.time_table;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
char branch1;
Spinner spbranch,spsem,spdiv;
ArrayAdapter<CharSequence>adapter;
ArrayAdapter<CharSequence>adapter1;
ArrayAdapter<CharSequence>adapter2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button Submit = (Button) findViewById(R.id.button);
spbranch = (Spinner)findViewById(R.id.spinner);
spsem = (Spinner)findViewById(R.id.spinner2);
spdiv = (Spinner)findViewById(R.id.spinner3);
adapter = ArrayAdapter.createFromResource(this,R.array.branch,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spbranch.setAdapter(adapter);
spbranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
int i;
// branch1=spbranch.getItemAtPosition(i).toString();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
adapter1 = ArrayAdapter.createFromResource(this,R.array.sem,android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spsem.setAdapter(adapter1);
adapter2 = ArrayAdapter.createFromResource(this,R.array.division,android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spdiv.setAdapter(adapter2);
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(view, "this is my Toast message!!! =)",
// Toast.LENGTH_LONG).show();
// Intent intent = new Intent(v.getContext(), nik.class);
// startActivityForResult(intent, 0);
}
});
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
layout...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main" tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Branch"
android:id="@+id/textView"
android:layout_marginTop="105dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp"
android:textSize="20dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_marginLeft="34dp"
android:layout_marginStart="34dp"
android:layout_alignTop="@+id/textView"
android:layout_alignLeft="@+id/button"
android:layout_alignStart="@+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sem"
android:id="@+id/textView2"
android:layout_below="@+id/spinner"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_marginTop="30dp"
android:textSize="20dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner2"
android:layout_alignTop="@+id/textView2"
android:layout_alignLeft="@+id/spinner"
android:layout_alignStart="@+id/spinner" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Division"
android:id="@+id/textView3"
android:layout_below="@+id/spinner2"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_marginTop="30dp"
android:textSize="20dp" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner3"
android:layout_alignTop="@+id/textView3"
android:layout_alignLeft="@+id/spinner2"
android:layout_alignStart="@+id/spinner2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/button"
android:layout_below="@+id/spinner3"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the details"
android:id="@+id/textView4"
android:textSize="20dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
当我按下提交按钮时,应该发生以下情况 例如 if(branch =='cs'&amp;&amp; sem =='5'&amp;&amp; div =='A') 那么新的活动
我该怎么做?
答案 0 :(得分:0)
您可以使用Spinner.getSelectedItem()
从三个微调器中获取当前选定的值,然后使用这些值来确定是否应启动Activity
。