我经常遇到x is in the set {1, 2, 3}
和EditTexts
的麻烦,因为我经常使用它们。我试图从可充气的edittext中获取输入的值并将它们放入ArrayList中,但显然,我收到的值始终是ArrayLists
。我怎样才能解决这个问题?
以下是我认为可行的代码:
0,0,0
如果您需要任何其他代码来帮助您解决这个问题,请将其放在评论中。
EDIT ::: ScoreList和TotalList的初始化看起来像
public void addCourses() {
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < this.coursesList.size(); i++) {
View v = inflater.inflate(R.layout.item_course, null, false);
this.courses.addView(v);
final int position = CalculateActivity.this.scoreList.size();
final int position2 = CalculateActivity.this.totalList.size();
CalculateActivity.this.scoreList.add(0);
EditText Score = (EditText) v.findViewById(R.id.Score);
EditText Total = (EditText) v.findViewById(R.id.Total);
Score.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable editable) {
percentage = Integer.parseInt(editable.toString());
int perc = (int) percentage;
CalculateActivity.this.scoreList.set(position, perc);
}
});
Total.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable editable) {
hundredth = Integer.parseInt(editable.toString());
int hund = (int) percentage;
CalculateActivity.this.scoreList.set(position2, hund);
}
});
}
}
此外,上面的代码在这里使用:
ArrayList<Integer> gradesList = new ArrayList();
ArrayList<Integer> scoreList = new ArrayList();
ArrayList<Integer> totalList = new ArrayList();
还有一个问题是,当我记录了scoreList或TotalList的ArrayList时,无论我输入什么值,这些值都会返回0,0,0。
答案 0 :(得分:1)
使用getText()。这会更简单。
FuncTickFormatter