2016-07-05 66 views
2
public class PerformanceDashboard extends MotherActivity { 

String dashboardData; 
int SELECTED_PAGE, SEARCH_TYPE, TRAY_TYPE; 
List<String[]> cachedCounterUpdates = new ArrayList<String[]>(); 
List<DasDetails> docList = new ArrayList<DasDetails>(); 
ListView listViewDashboard; 
DataAdapter dataAdap = new DataAdapter(); 
TextView noOfItems, userCount, totalLoginTime; 
int itemsTotal = 0, userTotal = 0, totalTime = 0; 
String KEYWORD = ""; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    if (App.isTestVersion) { 
     Log.e("actName", "StoreOut"); 
    } 

    if (bgVariableIsNull()) { 
     this.finish(); 
     return; 
    } 

    setContentView(R.layout.dashboard); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
    setProgressBarIndeterminateVisibility(false); 
    lytBlocker = (LinearLayout) findViewById(R.id.lyt_blocker); 
    listViewDashboard = (ListView) findViewById(R.id.dashboard_listview); 
    noOfItems = ((TextView) findViewById(R.id.noOfItems)); 
    userCount = ((TextView) findViewById(R.id.userCount)); 
    totalLoginTime = ((TextView) findViewById(R.id.totalLoginTime)); 

    new DataLoader().start(); 
    listViewDashboard.setAdapter(dataAdap); 

    System.out.println("PerformanceDashboard. onCreate processOutData() -- item total " + itemsTotal); //0 i am not getting that adapter value i.e. 6 
    System.out.println("PerformanceDashboard. onCreate processOutData() -- user total " + userTotal); //0 i am not getting that adapter value i.e. 4 
    System.out.println("PerformanceDashboard. onCreate processOutData() -- total total " + totalTime); //0 i am not getting that adapter value i.e. 310 

} 

private class DataAdapter extends BaseAdapter { 

    @Override 
    public int getCount() { 
     return docList.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return null; 
    } 

    @Override 
    public long getItemId(int position) { 
     return 0; 
    } 

    @Override 
    public View getView(final int position, View convertView, 
      ViewGroup parent) { 

     LayoutInflater li = getLayoutInflater(); 
     if (convertView == null) 
      convertView = li.inflate(R.layout.dashboard_item, null); 

     final DasDetails item = docList.get(position); 

     ((TextView) convertView.findViewById(R.id.cMode)) 
       .setText(item.cMode); 
     ((TextView) convertView.findViewById(R.id.noOfItems)) 
       .setText(item.totPickItemCount); 
     ((TextView) convertView.findViewById(R.id.userCount)) 
       .setText(item.userCount); 
     ((TextView) convertView.findViewById(R.id.totalLoginTime)) 
       .setText(item.totLoginTime); 

     TextView textView = ((TextView) convertView 
       .findViewById(R.id.avgSpeed)); 
     Double s = Double.parseDouble(item.avgPickingSpeed); 
     textView.setText(String.format("%.2f", s)); 
     if (position == 0 || position == 2 || position == 4) { 
      convertView.setBackgroundColor(getResources().getColor(
        R.color.hot_pink)); 
     } else if (position == 1 || position == 3 || position == 5) { 
      convertView.setBackgroundColor(getResources().getColor(
        R.color.lightblue)); 
     } 
     return convertView; 
    } 
} 

class ErrorItem { 

    String cMode, dDate, userCount, totLoginTime, totPickItemCount, 
      avgPickingSpeed; 

    public ErrorItem(HashMap<String, String> row) { 
     cMode = row.get(XT.MODE); 
     dDate = row.get(XT.DATE); 
     userCount = row.get(XT.USER_COUNT); 
     totLoginTime = row.get(XT.TOT_LOGIN_TIME); 
     totPickItemCount = row.get(XT.TOT_PICK_ITEM_COUNT); 
     avgPickingSpeed = row.get(XT.AVG_PICKING_SPEED); 

    } 

} 

private class DataLoader extends Thread { 

    @Override 
    public void run() { 
     super.run(); 

     System.out.println("DataLoader dashboard"); 

     List<NameValuePair> param = new ArrayList<NameValuePair>(); 

     param.add(new BasicNameValuePair(C.PRM_IDX, C.GET_SUMMARY)); 
     param.add(new BasicNameValuePair(C.PRM_HDR_DATA, "2016-07-04")); // yyyy-mm-dd 

     toggleProgressNoUINoBlock(true); 
     final String result = callService(C.WS_ST_PERFORMANCE_DASHBOARD, 
       param); 

     if (!App.validateXmlResult(actContext, null, result, true)) 
      return; 

     runOnUiThread(new Runnable() { 
      @Override 
      public void run() { 

       Runnable r = new Runnable() { 

        @Override 
        public void run() { 
         dataAdap.notifyDataSetChanged(); 
         toggleProgressNoUINoBlock(false); 
        } 
       }; 

       dashboardData = result; 
       processOutData(r); 

      } 

     }); 
    } 
} 

private String callService(String serviceName, List<NameValuePair> params) { 
    String result = ws.callService(serviceName, params); 
    return result; 
} 

private void processOutData(final Runnable rAfterProcessing) { 

    if (dashboardData == null || dashboardData.length() == 0) 
     return; 

    new Thread() { 
     @Override 
     public void run() { 
      super.run(); 

      final List<HashMap<String, String>> dataList = XMLfunctions 
        .getDataList(dashboardData, new String[] { XT.MODE, 
          XT.DATE, XT.USER_COUNT, XT.TOT_LOGIN_TIME, 
          XT.TOT_PICK_ITEM_COUNT, XT.AVG_PICKING_SPEED }); 

      final List<DasDetails> tempList = new ArrayList<DasDetails>(); 

      for (int i = 0; i < dataList.size(); i++) { 

       int pos = docExists(tempList, dataList.get(i).get(XT.MODE)); 
       if (pos == -1) { 
        if (SEARCH_TYPE == 0 
          || KEYWORD.equals("") 
          || (SEARCH_TYPE == 1 && dataList.get(i) 
            .get(XT.CUST_NAME).contains(KEYWORD)) 
          || (SEARCH_TYPE == 2 && dataList.get(i) 
            .get(XT.DOC_NO).contains(KEYWORD))) { 
         DasDetails doc = new DasDetails(dataList.get(i)); 

         int cachePos = getPosInCachedCounterUpdates(doc.cMode); 
         if (cachePos != -1) { 
          if (cachedCounterUpdates.get(cachePos)[1] 
            .equals(doc.dDate)) 
           cachedCounterUpdates.remove(cachePos); 
          else 
           doc.dDate = cachedCounterUpdates 
             .get(cachePos)[1]; 
         } 

         tempList.add(doc); 
         pos = tempList.size() - 1; 
        } 

       } 

       if (pos == -1) 
        continue; 
      } 

      runOnUiThread(new Runnable() { 

       @Override 
       public void run() { 
        docList = tempList; 
        rAfterProcessing.run(); 
        logit("processOutData", "Processing OVER"); 
       } 
      }); 
      for (int i = 0; i < docList.size(); i++) { 
       itemsTotal = itemsTotal+ Integer.parseInt(docList.get(i).totPickItemCount); 

       userTotal = userTotal + Integer.parseInt(docList.get(i).userCount); 

       totalTime = totalTime + Integer.parseInt(docList.get(i).totLoginTime); 

      } 
      System.out.println("PerformanceDashboard.processOutData() -- fINAL item TOTAL " + itemsTotal); // 6 i have data here but i need this data in my oncreate but not getting why????? 
      System.out.println("PerformanceDashboard.processOutData() -- userTotal TOTAL " + userTotal); //4 
      System.out.println("PerformanceDashboard.processOutData() -- totalTime TOTAL " + totalTime); //310 
      noOfItems.setText(itemsTotal); // crashing with null pointer exception 
      // userCount.setText(userTotal); 
      // totalLoginTime.setText(totalTime); 
     }; 
    }.start(); 

} 

private class DasDetails { 

    public String cMode, dDate, userCount, totLoginTime, totPickItemCount, 
      avgPickingSpeed; 

    public DasDetails(HashMap<String, String> data) { 
     cMode = data.get(XT.MODE); 
     dDate = data.get(XT.DATE); 
     userCount = data.get(XT.USER_COUNT); 
     totLoginTime = data.get(XT.TOT_LOGIN_TIME); 
     totPickItemCount = data.get(XT.TOT_PICK_ITEM_COUNT); 
     avgPickingSpeed = data.get(XT.AVG_PICKING_SPEED); 

    } 
} 

public Integer docExists(List<DasDetails> list, String docNo) { 

    for (int i = 0; i < list.size(); i++) { 
     if (list.get(i).cMode.equals(docNo)) 
      return i; 
    } 
    return -1; 
} 

private int getPosInCachedCounterUpdates(String docNo) { 
    for (int i = 0; i < cachedCounterUpdates.size(); i++) { 
     if (cachedCounterUpdates.get(i)[0].equals(docNo)) 
      return i; 
    } 
    return -1; 
} 

}無法設定值runonuithread

這是上面的代碼,請通過它,讓我知道是否需要任何澄清說明TextView的。我無法將「itemsTotal」值設置爲「noOfIttems」textview。我已添加評論。請幫我解決這個問題。 在此先感謝。

+0

您確定noOfItems textView不爲null嗎? 您可以確認,如果textView爲空或不是 –

+0

@intellignt_idiot ok等待 –

+0

而您的方法: noOfItems.setText(itemsTotal);它不在runOnUIThread中。再檢查一遍。 –

回答

2

請檢查您的noOfItems textView的ID。 TextView爲null。

+0

這是我的錯誤,謝謝你幫助我。 –