0
当我输入数据并按下按钮以启动下面的按钮时,我有3个字段创建三个动态输入字段,程序计算只有3个顶部字段的平均分数。我想,当用户改变了动态创建的字段中的任何数据从这些字段数的数据,而不管其数量在程序中从动态创建的EditText中获取文本
package com.example.averegemark;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TableRow.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
public class Table extends Activity {
LinearLayout LL;
EditText et1,et2,et3;
double coef=0,points=0,sum=0,coefsum=0;
TextView total;
Button bNext;
String name="",mark="",coeff="";
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.table);
bNext = (Button) findViewById(R.id.bNext);
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
et3 = (EditText) findViewById(R.id.et3);
total = (TextView) findViewById(R.id.tvTotal);
total.setText("GPA:");
LL = (LinearLayout) findViewById(R.id.LL);
bNext.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
name = et1.getText().toString();
mark = et2.getText().toString();
coeff = et3.getText().toString();
if(mark.length()==0 || coeff.length()==0)
Toast.makeText(getApplicationContext(), "Enter mark `and coefficient", Toast.LENGTH_LONG).show();
else
NewView(name,mark,coeff);
}
});
}
private void NewView(String name, String mark, String coeff) {
// TODO Auto-generated method stub
EditText info1 = new EditText(this);
EditText info2 = new EditText(this);
EditText info3 = new EditText(this);
info1.setId(i);i++;
info1.setId(i);i++;
info1.setId(i);i++;
info1.setText(""+name);
info2.setText(""+mark);
info3.setText(""+coeff);
TableLayout table = (TableLayout) findViewById(R.id.tbl);
table.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TableRow row = new TableRow(this);
row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
row.addView(info1);
row.addView(info2);
row.addView(info3);
table.addView(row);
String rez="";
rez= info2.getText().toString();
points = Double.parseDouble(rez);
rez= info3.getText().toString();
coef = Double.parseDouble(rez);
sum +=coef*points;
coefsum+=coef;
sum/=coefsum;
total.setText("GPA : "+sum+"\nCoefficient sum. "+coefsum);
et3.setText("");
et2.setText("");
et1.setText("");
et1.requestFocus();
}
}
所以当我将行更改任何数据,我想重新计算这一点,但在这里它只使用顶部EditText不动态创建:
String rez="";
rez= info2.getText().toString();
points = Double.parseDouble(rez);
rez= info3.getText().toString();
coef = Double.parseDouble(rez);
sum +=coef*points;
coefsum+=coef;
sum/=coefsum;
total.setText("GPA : "+sum+"\nCoefficient sum. "+coefsum);
我现在读了5次,我不明白。也许问题出在我身上,但如果你重新解释你的问题,这可能会有所帮助。 – stpn108
OKEY,你会看到,在布局中创建了3个EditText,每次当你输入数据并按下按钮时,它们下面会用相同的数据创建3个新的EditText。程序计算GPA =系数*标记\系数和; 我希望程序在用户每次更改动态创建的EditText中的某些数据时重新计算GPA。 对不起,对我来说很难正确地提出问题。 – CVS
私人无效getCount将(){ \t \t \t \t TableLayout表=(TableLayout)findViewById(R.id.tbl); \t \t \t \t ArrayList metl = new ArrayList (); \t \t \t \t尝试{ \t \t对(INT I = 0; I
CVS