Я новичок в разработке приложений для Android, так что это может быть легко для вас. Я обыскал этот форум до того, как я разместил его, поэтому, пожалуйста, взгляните, прежде чем отмечать его как дубликат. Я не объявляю статические переменные в методе updatestandard. Вот моя программа:Значение локальной переменной не используется?
package com.example.new1;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.text.TextWatcher;
import android.text.Editable;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class MainActivity extends ActionBarActivity {
private static final String BILL_TOTAL = "BILL_TOTAL";
private static final String CUSTOM_PERCENT = "CUSTOM_PERCENT";
private double currentBillTotal;
private int currentCustomPercent;
private EditText tip10EditText;
private EditText total10EditText;
private EditText tip15EditText;
private EditText total15EditText;
private EditText billEditText;
private EditText tip20EditText;
private EditText total20EditText;
private TextView customTipTextView;
private EditText tipCustomEditText;
private EditText totalCustomEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(savedInstanceState ==null)
{
currentBillTotal=0.0;
currentCustomPercent=0;
}
else
{
currentBillTotal=savedInstanceState.getDouble(BILL_TOTAL);
currentCustomPercent=savedInstanceState.getInt(CUSTOM_PERCENT);
}
tip10EditText=(EditText) findViewById(R.id.tip10editText);
tip15EditText=(EditText) findViewById(R.id.tip15editText);
tip20EditText=(EditText) findViewById(R.id.tip20editText);
total10EditText=(EditText) findViewById(R.id.totaltenEditText);
total20EditText=(EditText) findViewById(R.id.totaltwentyEditText);
total15EditText=(EditText) findViewById(R.id.totalfifteenEditText);
tipCustomEditText=(EditText) findViewById(R.id.tipcustomeditText);
totalCustomEditText=(EditText) findViewById(R.id.totaltcustomeditText);
billEditText=(EditText) findViewById(R.id.billeditText1);
billEditText.addTextChangedListener(billEditTextWatcher);
SeekBar customSeekBar = (SeekBar) findViewById(R.id.customSeekBar);
customSeekBar.setOnSeekBarChangeListener(customSeekBarListner);
customTipTextView = (TextView) findViewById(R.id.customTipTextView);
}
private void updateStandard()
{
double tenPercentTip= currentBillTotal * .1;
double tenPercentTotal = currentBillTotal+tenPercentTip;
total10EditText.setText(String.format("%.02f,tenPercentTotal"));
double fifteenPercentTip= currentBillTotal * .15;
double fifteenPercentTotal= currentBillTotal+fifteenPercentTip;
double twentyPercentTip= currentBillTotal * .20;
double twentyPercentTotal= currentBillTotal+twentyPercentTip;
tip10EditText.setText(String.format("%.02f",tenPercentTip));
tip15EditText.setText(String.format("%.02f",fifteenPercentTip));
total15EditText.setText(String.format("%.02f,fifteenPercentTotal"));
tip20EditText.setText(String.format("%.02f",twentyPercentTip));
total20EditText.setText(String.format("%.02f,twentyPercentTotal"));
}
private void updateCustom()
{
customTipTextView.setText(currentCustomPercent+"%");
double customTipAmount=currentBillTotal*currentCustomPercent*.01;
tipCustomEditText.setText(String.format("%.02f",customTipAmount));
double customTotalAmount=currentBillTotal+customTipAmount;
totalCustomEditText.setText(String.format("%.02f",customTotalAmount));
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putDouble(BILL_TOTAL, currentBillTotal);
outState.putInt(CUSTOM_PERCENT, currentCustomPercent);
}
private OnSeekBarChangeListener customSeekBarListner=new OnSeekBarChangeListener()
{
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
currentCustomPercent=seekBar.getProgress();
updateCustom();
// TODO Auto-generated method stub1
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
};
private TextWatcher billEditTextWatcher=new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
try
{
currentBillTotal=Double.parseDouble(s.toString());
}
catch(NumberFormatException e)
{
currentBillTotal=0.0;
}
updateStandard();
updateCustom();
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
};
@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);
}
}
так в затмении он говорит в стандартных линиях обновления, что переменные не использовал tenPercentTotal, fifteenPercentTotal и twentyPercentTotal ИДК, почему он говорит, что они используются в следующем линии под ним PLS помочь этой точной программе, работая до того, как я щелкнул правой кнопкой мыши мой проект и выбрал вариант экспорта приложений для Android, который перепутал многие вещи, что произошло.
Ваше закрытие «находится в неправильном положении для некоторых ваших вызовов String.format –