当我在第一个活动中单击“温度”按钮时,我的第二个活动打开,其中有两个名为“从广告到”的微调器。我想给旋转器的条件,但我的if循环不能工作,循环直接转到其他条件。如果有的话请告诉mi问题或给我解决方案。提前谢谢。
package com.example.omkar.allinoneconverter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class TemperatureActivity extends AppCompatActivity {
Spinner spinner_temperature_from;
ArrayAdapter adapter_temperature_from;
Spinner spinner_temperature_to;
ArrayAdapter adapter_temperature_to;
String spinner_temperature_from_value;
String spinner_temperature_to_value;
Button button_temperature_convert;
EditText temperature_value;
TextView result_text_for_temperature;
String get_temperature_value;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temperature);
spinner_temperature_from= (Spinner) findViewById(R.id.temperature_from);
adapter_temperature_from=ArrayAdapter.createFromResource(this,R.array.spinner_temperature_from,android.R.layout.simple_spinner_item);
adapter_temperature_from.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_temperature_from.setAdapter(adapter_temperature_from);
spinner_temperature_to=(Spinner)findViewById(R.id.temperature_to);
adapter_temperature_to=ArrayAdapter.createFromResource(this,R.array.spinner_temperature_to,android.R.layout.simple_spinner_item);
adapter_temperature_to.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_temperature_to.setAdapter(adapter_temperature_to);
OnClickOfConvert();
}
public void OnClickOfConvert(){
temperature_value=(EditText)findViewById(R.id.temperature_value);
get_temperature_value=temperature_value.getText().toString();
button_temperature_convert=(Button)findViewById(R.id.button_temperature_convert);
result_text_for_temperature=(TextView)findViewById(R.id.result_text_for_temperature);
spinner_temperature_from_value=spinner_temperature_from.getSelectedItem().toString();
spinner_temperature_to_value=spinner_temperature_to.getSelectedItem().toString();
button_temperature_convert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(spinner_temperature_from_value.equals("Kelvin")&&spinner_temperature_to_value.equals("Kelvin")) {
button_temperature_convert.setText("If Works!");
}
else{
result_text_for_temperature.setText("If Condition Not Working But Else Work's Fine!");
}
}
});
}
@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_temperature, 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);
}
}