总结一下,我有一个listview
,列表视图中的每个项目都有一个button
。按钮可以处于两种状态:突出显示或不突出显示。我在屏幕底部还有一个edittext
,其中包含用于显示结果的桩和文本视图。每个button
文本都包含一个双精度数;当按钮处于突出显示状态时,桩号乘以按钮上的双倍,结果显示在文本视图中。如果突出显示多个按钮,则结果为所有突出显示的按钮。当用户更改赌注时,结果会动态变化;这是使用下面的代码和onTextChangedListener完成的。当用户首先输入赌注然后进行选择时,一切都很好。但是,我的问题是,当用户FIRST使用edittext为空时进行选择并且AFTER将比特输入到edittext中时没有反应;然后,用户必须重新选择他所有的选择,以使系统正常工作。我正在寻找有关如何更改以下代码以解决此问题的建议,并使应用程序以相同的方式运行,无论是先输入赌注还是首先进行选择。单击列表视图中的任何按钮时,将执行以下方法。我们关注的editText是变量mEdit
。其余代码与问题无关,但我将其包含在内以避免混淆。
@Override
public void onClick(View v) {
LinearLayout layout = (LinearLayout) v;
Button b = (Button) layout.findViewById(R.id.oddsbutton);
ListView listView = (ListView) layout.getParent();
final int position = listView.getPositionForView(listView);
String buttontext = b.getText().toString();
Button lastchance = (Button) layout.findViewById(R.id.oddsbutton);
TextView betidtextbox = (TextView) layout.findViewById(R.id.gid);
String betid = betidtextbox.getText().toString();
TipDisplayer currentwriter = alltips.get(position + 1);
Log.d("new", newBet.toString());
if (ids.contains(Integer.parseInt(betid))) {
b.setTextColor(Color.parseColor("#000000"));
b.setTextSize(18);
ids.remove(new Integer(Integer.parseInt(betid)));
Log.d("new", newBet.toString());
currentwriter.toggleHighlighted();
//checkhighlight(layout);
Log.d("getodds", buttontext);
selection = "home";
TextView teamss = (TextView) layout.findViewById(R.id.teamstxt);
String teams = teamss.getText().toString();
Log.d("teams", teams);
TextView bet = (TextView) layout.findViewById(R.id.bettxt);
String bettxt = bet.getText().toString();
Log.d("btxttext", bettxt);
newBet.generateoddstesting(betid, buttontext, false, teams, selection, bettxt);
double newodds = newBet.calculateodds();
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
EditText mEdit = (EditText) findViewById(R.id.editText2);
if (mEdit.getText().toString().length() == 0) {
stake = 0.00;
newwinnings = 0.00;
potentialWinnings.setText("0.00");
} else {
mEdit.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if (s.length() != 0) {
stake = Double.parseDouble(s.toString());
double newodds = newBet.calculateodds();
newwinnings = stake * newodds;
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
} else {
stake = 0.00;
newwinnings = 0.00;
double newodds = newBet.calculateodds();
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
}
}
public void afterTextChanged(Editable s) {
}
});
//stake = Double.parseDouble(mEdit.getText().toString());
newwinnings = stake * newodds;
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
}
} else {
ids.add(Integer.parseInt(betid));
//checkhighlight(layout);
b.setTextColor(Color.parseColor("#EB102E"));
b.setTextSize(20);
currentwriter.toggleHighlighted();
selection = "home";
String getodds = lastchance.getText().toString();
Log.d("getoddsss", getodds);
EditText mEdit = (EditText) findViewById(R.id.editText2);
if (mEdit.getText().toString().length() == 0) {
stake = 0.00;
newwinnings = 0.00;
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
potentialWinnings.setText("0.00");
} else {
mEdit.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if (s.length() != 0) {
stake = Double.parseDouble(s.toString());
double newodds = newBet.calculateodds();
newwinnings = stake * newodds;
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
} else {
stake = 0.00;
double newodds = newBet.calculateodds();
newwinnings = stake * newodds;
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
}
}
public void afterTextChanged(Editable s) {
}
});
stake = Double.parseDouble(mEdit.getText().toString());
TextView teamms = (TextView) layout.findViewById(R.id.teamstxt);
String teams = teamms.getText().toString();
Log.d("teams", teams);
TextView bet = (TextView) layout.findViewById(R.id.bettxt);
String bettxt = (String) bet.getText().toString();
Log.d("bettxt", bettxt);
newBet.generateoddstesting(betid, buttontext, true, teams, selection, bettxt);
double newodds = newBet.calculateodds();
newwinnings = stake * newodds;
TextView myBetOdds = (TextView) findViewById(R.id.bettingodds);
TextView potentialWinnings = (TextView) findViewById(R.id.potentialwinnings);
myBetOdds.setText("@" + String.format("%.2f", newodds) + "/1");
potentialWinnings.setText(String.format("%.2f", (newwinnings)));
newwinningstoString = potentialWinnings.getText().toString();
}
}
}
});