我需要帮助的第一个变量是totalTxt。此变量保存用户在先前类别中输入的所有金额的值。此变量应显示在“您的总支出为:”旁边。我需要帮助的第二个变量是still2。此变量保存用户目标的值并从中减去totalTxt。它应显示在“您需要保存:”旁边。我是如何实现ScrollView的呢?我尝试将其添加到布局中,但在模拟器上我无法滚动,因此“你需要保存:”被切断了。下面是我的代码...请帮助。
公共类MainActivity扩展了Activity实现OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
Button calculate = (Button) findViewById(R.id.calculate);
calculate.setOnClickListener(this);
}
@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);
}
@Override
public void onClick(View v) {
EditText goal = (EditText) findViewById (R.id.GoalText);
double goalTxt = Double.parseDouble(goal.getText().toString());
EditText groceries = (EditText) findViewById (R.id.GroceriesText);
double groceriesTxt = Double.parseDouble(groceries.getText().toString());
EditText rent = (EditText) findViewById (R.id.RentText);
double rentTxt = Double.parseDouble(rent.getText().toString());
EditText utilities = (EditText) findViewById (R.id.UtilitiesText);
double utilitiesTxt = Double.parseDouble(utilities.getText().toString());
EditText clothingshoesetc = (EditText) findViewById (R.id.ClothingShoesEtcText);
double clothingshoesetcTxt = Double.parseDouble(clothingshoesetc.getText().toString());
EditText entertainmentdiningetc = (EditText) findViewById (R.id.EntertainmentDiningEtcText);
double entertainmentdiningetcTxt = Double.parseDouble(entertainmentdiningetc.getText().toString());
EditText transportationcabtraingas = (EditText) findViewById (R.id.TransportationCabTrainGasText);
double transportationcabtraingasTxt = Double.parseDouble(transportationcabtraingas.getText().toString());
EditText others = (EditText) findViewById (R.id.OthersText);
double othersTxt = Double.parseDouble(others.getText().toString());
EditText total = (EditText) findViewById (R.id.YourTotalSpendingText);
double totalTxt = groceriesTxt + rentTxt + utilitiesTxt + clothingshoesetcTxt +
entertainmentdiningetcTxt + transportationcabtraingasTxt + othersTxt;
Toast.makeText(getApplicationContext(), Double.toString(totalTxt), Toast.LENGTH_LONG).show();
EditText still2= (EditText) findViewById (R.id.YouNeedToSaveText);
double still = goalTxt - totalTxt;
Toast.makeText (getApplicationContext (), Double.toString(still), Toast.LENGTH_LONG).show();
if (still < 0){
String stop = ("STOP SPENDING SO MUCH MONEY!");
Toast.makeText(getApplicationContext(), (stop), Toast.LENGTH_LONG).show(); }
if (still > 0) {
String go = ("Keep going! Piggy B. believes in you!");
Toast.makeText(getApplicationContext(), (go), Toast.LENGTH_LONG).show(); }
}
}
答案 0 :(得分:0)
在你的布局xml中,我猜测你有一个围绕EditTexts集合的LinearLayout(或一些布局)。
在布局xml文件中添加围绕LinearLayout的ScrollView。类似的东西:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/GoalText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
other edit text tags here
</LinearLayout>
</ScrollView>
添加ScrollView使用户可以滚动屏幕(如果视图大于屏幕)。