Exemplo n.º 1
0
 @JavascriptInterface
 public void onSelectTrains(String info) {
   final List<Train> trains = Utils.getTrainInfos(info);
   int count = trains.size();
   String[] items = new String[count];
   boolean checkedItems[] = new boolean[count];
   for (int i = 0; i < items.length; i++) {
     items[i] = trains.get(i).toString();
     checkedItems[i] = false;
   }
   final List<String> selectedTrainNumbers = new ArrayList<String>();
   builder.setMultiChoiceItems(
       items,
       checkedItems,
       new OnMultiChoiceClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which, boolean isChecked) {
           if (isChecked) {
             selectedTrainNumbers.add(trains.get(which).name);
           } else {
             selectedTrainNumbers.remove(trains.get(which).name);
           }
         }
       });
   builder.setPositiveButton(
       "确定",
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           mSelectedTrainNumbers = selectedTrainNumbers;
           Log.e("lkt", "selected train:" + mSelectedTrainNumbers.toString());
         }
       });
   builder.create().show();
 }
Exemplo n.º 2
0
 @JavascriptInterface
 public void onCheckInfo(String info) {
   trains = Utils.getTrainInfos(info);
   boolean foundTicket = false;
   for (int i = 0; i < trains.size(); i++) {
     Train t = trains.get(i);
     if (mSelectedTrainNumbers.contains(t.name) && t.hasSeat) {
       foundTicket = true;
       break;
     }
   }
   if (foundTicket) {
     onTicketFound();
   } else {
     startNextRefresh();
   }
 }