Java 无法在runonuithread中将值设置为textview 公共类PerformanceDashboard扩展了MotherActivity{ 字符串仪表板数据; int所选页面、搜索类型、托盘类型; List CachedCounterUpdate=n

Java 无法在runonuithread中将值设置为textview 公共类PerformanceDashboard扩展了MotherActivity{ 字符串仪表板数据; int所选页面、搜索类型、托盘类型; List CachedCounterUpdate=n,java,android,multithreading,textview,runnable,Java,Android,Multithreading,Textview,Runnable,无法在runonuithread中将值设置为textview 公共类PerformanceDashboard扩展了MotherActivity{ 字符串仪表板数据; int所选页面、搜索类型、托盘类型; List CachedCounterUpdate=new ArrayList(); List docList=new ArrayList(); ListView listViewDashboard; DataAdapter dataAdap=新的DataAdapter(); TextView n

无法在runonuithread中将值设置为textview
公共类PerformanceDashboard扩展了MotherActivity{
字符串仪表板数据;
int所选页面、搜索类型、托盘类型;
List CachedCounterUpdate=new ArrayList();
List docList=new ArrayList();
ListView listViewDashboard;
DataAdapter dataAdap=新的DataAdapter();
TextView noOfItems、userCount、totalLoginTime;
int itemsTotal=0,userTotal=0,totalTime=0;
字符串关键字=”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
如果(App.isTestVersion){
Log.e(“actName”、“StoreOut”);
}
if(bgVariableIsNull()){
这个;
返回;
}
setContentView(R.layout.dashboard);
getWindow().addFlags(WindowManager.LayoutParams.FLAG\u保持屏幕打开);
SetProgressBarInDeterminateVibility(假);
lytBlocker=(线性布局)findViewById(R.id.lyt_拦截器);
listViewDashboard=(ListView)findViewById(R.id.dashboard\u ListView);
noOfItems=((TextView)findViewById(R.id.noOfItems));
userCount=((TextView)findViewById(R.id.userCount));
totalLoginTime=((TextView)findViewById(R.id.totalLoginTime));
新数据加载器().start();
setAdapter(dataAdap);
System.out.println(“PerformanceDashboard.onCreate processOutData()--item total”+itemsTotal);//0我没有得到适配器值,即6
System.out.println(“PerformanceDashboard.onCreate processOutData()--user total”+userTotal);//0我没有得到适配器值,即4
System.out.println(“PerformanceDashboard.onCreate processOutData()--total总计”+totalTime);//0我没有得到适配器值,即310
}
私有类DataAdapter扩展了BaseAdapter{
@凌驾
public int getCount(){
返回docList.size();
}
@凌驾
公共对象getItem(int位置){
返回null;
}
@凌驾
公共长getItemId(int位置){
返回0;
}
@凌驾
公共视图getView(最终整型位置,视图转换视图,
视图组(父级){
LayoutInflater li=getLayoutInflater();
if(convertView==null)
convertView=li.充气(R.布局.仪表板_项,空);
最终数据详细项=docList.get(位置);
((TextView)convertView.findViewById(R.id.cMode))
.setText(项目.cMode);
((TextView)convertView.findViewById(R.id.noOfItems))
.setText(item.totPickItemCount);
((TextView)convertView.findViewById(R.id.userCount))
.setText(item.userCount);
((TextView)convertView.findViewById(R.id.totaloginitime))
.setText(项totlogentime);
TextView TextView=((TextView)convertView
.findviewbyd(R.id.avgSpeed));
Double s=Double.parseDouble(item.avgPickingSpeed);
setText(String.format(“%.2f”,s));
如果(位置==0 | |位置==2 | |位置==4){
convertView.setBackgroundColor(getResources().getColor(
R.color.hot_-pink);
}else if(位置==1 | |位置==3 | |位置==5){
convertView.setBackgroundColor(getResources().getColor(
R.颜色(浅蓝色);
}
返回视图;
}
}
类错误项{
字符串cMode、dDate、userCount、totLoginTime、totPickItemCount、,
avgPickingSpeed;
公共错误项(哈希映射行){
cMode=row.get(XT.MODE);
dDate=row.get(XT.DATE);
userCount=row.get(XT.USER\u COUNT);
totlogentime=row.get(XT.TOT\u LOGIN\u TIME);
totPickItemCount=row.get(XT.TOT\u PICK\u ITEM\u COUNT);
avgPickingSpeed=row.get(XT.AVG\u pickingspeed);
}
}
私有类数据加载器扩展线程{
@凌驾
公开募捐{
super.run();
System.out.println(“DataLoader仪表板”);
List param=new ArrayList();
参数add(新的BasicNameValuePair(C.PRM_IDX,C.GET_SUMMARY));
参数添加(新的BasicNameValuePair(C.PRM_HDR_数据,“2016-07-04”);//yyyy-mm-dd
toggleProgressNoUINoBlock(真);
最终字符串结果=callService(C.WS\u ST\u性能\u仪表板,
参数);
如果(!App.validateXmlResult(actContext,null,result,true))
返回;
runOnUiThread(新的Runnable(){
@凌驾
公开募捐{
Runnable r=新的Runnable(){
@凌驾
公开募捐{
dataAdap.notifyDataSetChanged();
toggleProgressNoUINoBlock(假);
}
};
仪表板数据=结果;
processOutData(r);
}
});
}
}
私有字符串调用服务(字符串服务名称,列表参数){
字符串结果=ws.callService(serviceName,params);
返回结果;
}
私有void processOutData(最终可运行的rAfterProcessing){
如果(dashboardData==null | | dashboardData.length()==0)
返回;
新线程(){
@凌驾
公开募捐{
super.run();
最终列表dataList=XMLfunctions
.getDataList(仪表板数据,新字符串[]{XT.MODE,
XT.DATE,XT.USER\u COUNT,XT.TOT\u LOGIN\u TIME,
XT.TOT_PICK_ITEM_COUNT,XT.AVG_PICK_SPEED});
最终列表模板列表=新的ArrayList();
对于(int i=0;ipublic 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;
}