我试图在应用程序中接收用户输入,代表彩票中的数字,然后可以将其与网站上的数字进行比较。我已经使用 JSoup 库来解析来自网站的数字,但我正在努力接收用户对应用程序的输入。我使用 EditText 对象来允许用户输入他们的数字,但目前我的应用程序只显示用户输入的结果。我想知道如何接收可以与彩票号码进行比较的输入。任何人都可以请帮忙。
我的代码如下:
public class StartingPoint extends Activity {
public final static String EXTRA_MESSAGE = ".com.spc.checklotterynumbers.MESSAGE";
final Context context = this;
private EditText edittext;
int lotteryNumbers;
Button check;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
}//onCreate
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.starting_point, menu);
return true;
}//onCreateOptionsMenu
/**Called when the user clicks the send button*/
public void checkNumbers(View view) {
//Do something in response to button
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}//checkNumbers
public static void main (String [] args){
//link to the intended web site
try {
Document doc = Jsoup.connect("http://www.national-lottery.co.uk/player/p/drawHistory.do").get();
Elements elements = doc.getElementsByClass("drawhistory");
Element table = elements.first();
Element tbody = table.getElementsByTag("tbody").first();
Element firstLottoRow = tbody.getElementsByClass("lottorow").first();
Element dateElement = firstLottoRow.child(0);
System.out.println(dateElement.text());
Element gameElement = firstLottoRow.child(1);
System.out.println(gameElement.text());
Element noElement = firstLottoRow.child(2);
System.out.println(noElement.text());
String [] split = noElement.text().split(" - ");
// set up an array to store numbers from the latest draw on the lottery web page
Integer [] numbers = new Integer [split.length];
int i = 0;
for (String strNo : split) {
numbers [i] = Integer.valueOf(strNo);
i++;
}
for (Integer no : numbers) {
System.out.println(no);
}
Element bonusElement = firstLottoRow.child(3);
Integer bonusBall = Integer.valueOf(bonusElement.text());
System.out.println("Bonus ball: " + bonusBall);
//Elements elementsHtml = doc.getElementsByTag("main-article-content");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}