我一直無法弄清楚,但我試圖做的是將我的應用程序中的幾個雙變量轉換爲字符串。我不完全確定如何在我目前的代碼中做到這一點。我一直得到「不能在原始類型double中調用isChecked()」。我無法找到任何教程解釋如何做到這一點,所以原諒我。這裏是我的代碼,任何提示將不勝感激:將double轉換爲單選按鈕的字符串
package net.androidbootcamp.zipcarrentalapp;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity
{
private RadioGroup radioGroupId;
private RadioButton radioButton;
private Button button;
final RadioButton Compact = (RadioButton)findViewById(R.id.radCompact);
final RadioButton MidSize = (RadioButton)findViewById(R.id.radMidSize);
final RadioButton Luxury = (RadioButton)findViewById(R.id.radLuxury);
final TextView result = (TextView) findViewById(R.id.txtResult);
double radCompact = 59.99;
double radMidSize = 65.99;
double radLuxury = 89.99;
int days = 0;
double computeValue;
public void operation(int days)
{
if(days <= 10)
{
if(radCompact.isChecked())
{
computeValue = radCompact * days;
txtResult.setText("Cost:" + Double.toString(computeValue));
}
else if (radMidSize.isChecked())
{
computeValue = radMidSize * days;
txtResult.setText("Cost: " + Double.toString(computeValue));
}
else if (radLuxury.isChecked())
{
computeValue = radLuxury * days;
txtResult.setText("Cost:" + Double.toString(computeValue));
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
}
太感謝你了,它固定它。我感謝所有的幫助:) – 2014-10-12 01:32:03
@AverageJoe編輯。 – 2014-10-12 01:34:24