我有一个应用程序,护理人员可以使用该应用程序来获取特定日期的名单。用户在日期选择器中设置日期。此日期将传递给名为 NfcScannerActivity 的活动。此活动使用该日期调用 Web 服务以获取列表。轮换数据是一个数组。NfcScannerActivity 将此数组传递给 GetRota,GetRota 是一个具有数组适配器的活动,该适配器用于显示轮播数据。
所有这一切都很好,直到在 GetRota 的 getView 方法中我检查是否没有特定日期的数据。在这一点上,我向用户敬酒,说明这一事实,然后用另一个日期(希望是一个有效的日期)重新调用 NfcScannerActivity。如果没有数据,则 getView 方法似乎执行两次,因为用户被烤了两次。为什么是这样?
NfcScannerActivity 的片段:
if(intent.getAction().equalsIgnoreCase("NEXT_ROTA")){
Log.e(TAG, "next rota action");
String date = intent.getStringExtra("nextRota");
getNextRota(date);
}
private void getNextRota(String stringExtra) {
String[] params = new String[]{nfcscannerapplication.getCarerID(), stringExtra};
AsyncGetRota agr = new AsyncGetRota();
agr.execute(params);
}
//////////snippet of async result of webservice call
...........
..........
@Override
protected void onPostExecute(Void result)
{
super.onPostExecute(result);
if(progressDialog != null)
progressDialog.dismiss();
if(isRotaArrayNull == false){
Intent intent = new Intent(NfcscannerActivity.this,
GetRota.class);
Bundle b = new Bundle();
b.putSerializable("rotaArray", rotaArray);
intent.putExtra("rotaArrayBundle", b);
startActivity(intent);
}else{...........
...........
.
来自 GetRota 的片段,显示 rota 的活动
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
super.onNewIntent(intent);
}
@Override
protected void onResume(){
super.onResume();
Log.e(TAG, "global date in onresume getrota = " + nfcscannerapplication.getglobalDateTime());
array = (ArrayList<String[]>)getIntent().getBundleExtra("rotaArrayBundle").get("rotaArray");
Log.e(TAG, "array size in onresume = " + array.size());
..............
...............
/////////adapter class in getrota
private class MySimpleArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<?> list;
public MySimpleArrayAdapter(Context context, ArrayList<?> list) {
super(context, R.layout.rotarowlayout);
Log.e(TAG, "inside adapter constructor");
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rotarowlayout, parent,
false);
TextView startTime = (TextView) rowView
.findViewById(R.id.rowstarttime);
TextView duration = (TextView) rowView
.findViewById(R.id.rowduration);
TextView status = (TextView) rowView.findViewById(R.id.rowstatus);
TextView name = (TextView) rowView.findViewById(R.id.rowclientname);
//ImageView imageView = (ImageView)rowView.findViewById(R.id.rowimagestatus);
String record = list.get(position).toString();
rowView.setTag(record);
String[] itemsInRecord = record.split(",");
Log.e(TAG, "itemin record = " + itemsInRecord.length);
String[] recordItem = new String[itemsInRecord.length];
for (int x = 0; x < itemsInRecord.length; x++) {
recordItem[x] = itemsInRecord[x];
}
if(recordItem[9].toString().trim().equalsIgnoreCase("Out of range]")){
Toast.makeText(GetRota.this, "No rota available", Toast.LENGTH_LONG).show();
nfcscannerapplication.setGobalDateTime(new DateTime());
//onBackPressed();
DateTime globalDateTime = nfcscannerapplication.getglobalDateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
String formattedglobalDateTime = fmt.print(globalDateTime);
Intent i = new Intent(GetRota.this, NfcscannerActivity.class);
i.putExtra("nextRota", formattedglobalDateTime);
i.setAction("NEXT_ROTA");
startActivity(i);
}else if(recordItem[0].toString().trim().equalsIgnoreCase("[nodata")){
Toast.makeText(GetRota.this, "You have no calls", Toast.LENGTH_LONG).show();
Log.e(TAG, "you have no calls");
nfcscannerapplication.setGobalDateTime(new DateTime());
//onBackPressed();
DateTime globalDateTime = nfcscannerapplication.getglobalDateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("d-MMM-Y");
String formattedglobalDateTime = fmt.print(globalDateTime);
Intent i = new Intent(GetRota.this, NfcscannerActivity.class);
i.putExtra("nextRota", formattedglobalDateTime);
i.setAction("NEXT_ROTA");
startActivity(i);