Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created July 27, 2016 15:34
Show Gist options
  • Save AungWinnHtut/ec25456232311e29780dff15ce9e8017 to your computer and use it in GitHub Desktop.
Save AungWinnHtut/ec25456232311e29780dff15ce9e8017 to your computer and use it in GitHub Desktop.
package com.example.spinnertest;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
private Spinner spinner1, spinner2;
private Button btnSubmit;
int x=0; int y=0;
Double [][] values ={
{(Double) 1.1,(Double) 2.2,(Double) 3.3},
{(Double) 4.4,(Double) 5.5,(Double) 6.6},
{(Double) 7.7,(Double) 8.8,(Double) 9.9}};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spinner1 = (Spinner) findViewById(R.id.firstSpinner);
spinner2 = (Spinner) findViewById(R.id.secondSpinner);
btnSubmit = (Button) findViewById(R.id.button1);
List<String> list = new ArrayList<String>();
list.add("list 1");
list.add("list 2");
list.add("list 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(dataAdapter);
btnSubmit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(getApplicationContext(),
"OnClickListener : " +
"\nSpinner 1 : "+ String.valueOf(spinner1.getSelectedItem()) +
"\nSpinner 2 : "+ String.valueOf(spinner2.getSelectedItem()),
Toast.LENGTH_SHORT).show();
String result = String.valueOf(spinner2.getSelectedItem());
String result1 = String.valueOf(spinner1.getSelectedItem());
if(result.equals("list 1"))
{
y=0;
// Toast.makeText(getApplicationContext(),"list 11111",Toast.LENGTH_SHORT).show();
}
else if(result.equals("list 2"))
{
y=1;
// Toast.makeText(getApplicationContext(),"list 2222",Toast.LENGTH_SHORT).show();
}
else if(result.equals("list 3"))
{
y=2;
//Toast.makeText(getApplicationContext(),"list 3333",Toast.LENGTH_SHORT).show();
}
if(result1.equals("Malaysia"))
{
x=0;
//Toast.makeText(getApplicationContext(),"Malaysia",Toast.LENGTH_SHORT).show();
}
else if(result1.equals("United States"))
{
x=1;
// Toast.makeText(getApplicationContext(),"United States",Toast.LENGTH_SHORT).show();
}
else if(result1.equals("Indonesia"))
{
x=2;
//Toast.makeText(getApplicationContext(),"Indonesia",Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(),"Value[x="+String.valueOf(x)+"][y="+String.valueOf(y)+"]="+String.valueOf(values[x][y]),Toast.LENGTH_SHORT).show();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment