Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android文本不可见_Android_User Interface - Fatal编程技术网

android文本不可见

android文本不可见,android,user-interface,Android,User Interface,我正在从应用程序向服务器发送一些信息,并等待响应。在发送之前,我将消息的文本视图设置为显示“处理请求”,在收到响应之后,我会显示不同的消息 未显示此处理消息。是否因为其他操作导致UI被阻塞。 如何处理这个问题。由于需要显示响应,线程未给出正确的结果。 因此,线程中包含UI package com.PandG.app.android.activities; import java.io.BufferedReader; import java.io.InputStream; import jav

我正在从应用程序向服务器发送一些信息,并等待响应。在发送之前,我将消息的文本视图设置为显示“处理请求”,在收到响应之后,我会显示不同的消息

未显示此处理消息。是否因为其他操作导致UI被阻塞。 如何处理这个问题。由于需要显示响应,线程未给出正确的结果。 因此,线程中包含UI

 package com.PandG.app.android.activities;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.PandG.app.android.R;
import com.PandG.app.android.dataAccess.SettingsDBAccess;
import com.PandG.app.android.entity.Job;
import com.PandG.app.android.entity.Settings;
import com.PandG.app.android.services.JobsManager;
import com.lib.android.Utils.Utils;
import com.lib.android.activity.BaseActivity;
import com.lib.android.dataAccess.DatabaseManager;

public class JobCheckoutActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setViewContent();
    }

    private void setViewContent() {

        Settings setting = getSettings();
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.job_checkout);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
        //new DataProcess().execute(null);
        TextView text1 = (TextView)findViewById(R.id.checkoutmessage);
        text1.setText("Processiong Job Cart ...");
        if(setting!=null){
            TextView text2 = (TextView)findViewById(R.id.checkoutheading);
            text2.setVisibility(View.GONE);
            Button homeButton = (Button)findViewById(R.id.gohome);
            homeButton.setVisibility(View.GONE);
        JSONObject jobObject =encodeData(setting);
        sendDataToServer(jobObject);
        } 

    }
    private void sendDataToServer(JSONObject jobObject) {
        TextView text1 = (TextView)findViewById(R.id.checkoutmessage);
        text1.setText("Processiong Job Cart ...");
        HttpClient client = new DefaultHttpClient();
        HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
                                                                                // Limit
        HttpResponse response;
        try {
            HttpPost post = new HttpPost(Utils.getPostUrl());
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("orderparameters",
                    jobObject.toString()));
            Log.i("Job ORDER", jobObject.toString());
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = client.execute(post);
            checkResponseFromServer(response);
            ClearCart();
        } catch (Exception e) {
            Log.w("error", "connection failed");
            Toast.makeText(this, "Order not placed due to connection error",
                    Toast.LENGTH_LONG);
            e.printStackTrace();

        }

    }

    private void ClearCart() {
        JobsManager.JobsCartList.clear();

    }

    private void checkResponseFromServer(HttpResponse response) {
        try {
            if (response != null) {
                InputStream in = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(in));

                String line;
                StringBuffer buffer = new StringBuffer();

                while ((line = reader.readLine()) != null) {
                    buffer.append(line);

                }

                in.close();

                JSONObject jsonResponse = new JSONObject(buffer.toString());
                Log.i("Status", jsonResponse.getString("status"));
                Log.i("Status", jsonResponse.getString("message"));
                Log.i("Status", jsonResponse.getString("debug"));
                TextView text1 = (TextView)findViewById(R.id.checkoutheading);
                text1.setVisibility(View.VISIBLE);
                TextView text = (TextView) findViewById(R.id.checkoutmessage);
                if (jsonResponse.getString("status").equals("SUCC")) {
                    text.setText( Html.fromHtml(getString(R.string.checkout_body1)));
                } else
                    text.setText(jsonResponse.getString("message")
                            + jsonResponse.getString("debug")); 

            }
        } catch (Exception ex) {

        }
    }


    private JSONObject encodeData(Settings setting) {
        JSONObject jobObject = new JSONObject();
        try {
            JSONObject jobject = new JSONObject();
            jobject.put("name", setting.getName());
            jobject.put("email", setting.getEmail());
            jobject.put("phone", setting.getPhone());
            jobject.put("school", setting.getSchool());
            jobject.put("major", setting.getMajor());

            jobObject.put("customer", jobject);
            JSONArray jobsarray = new JSONArray();
            for (Job job : JobsManager.JobsCartList) {
                JSONObject jobEntry = new JSONObject();
                jobEntry.put("jobtitle",job.getTitle());
                jobEntry.put("qty","1");
                jobsarray.put(jobEntry);
            }
            jobObject.put("orders", jobsarray);
        } catch (JSONException ex) {

        }
        return jobObject;
    }


    private Settings getSettings() {
        SettingsDBAccess settingsDBAccess = new SettingsDBAccess(
                DatabaseManager.getInstance());

        Settings setting = settingsDBAccess.getSetting();
        if (setting==null){
                startActivityForResult((new Intent(this,SettingsActivity.class)),Utils
                        .getDefaultRequestCode());
        }
        return setting;
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        Settings setting = new SettingsDBAccess(
                DatabaseManager.getInstance()).getSetting();
        if(setting!=null){
            JSONObject jobObject = encodeData(setting);
            sendDataToServer(jobObject);
        }

    }
/*  private class DataProcess extends AsyncTask {
        @Override
        protected void onPostExecute(Object result) {

        }

        @Override
        protected Object doInBackground(Object... arg0) {
            processDataandsend();
            return null;
        }

        private void processDataandsend() {
            Settings setting = getSettings();

            if(setting!=null){
                TextView text2 = (TextView)findViewById(R.id.checkoutheading);
                text2.setVisibility(View.GONE);
                Button homeButton = (Button)findViewById(R.id.gohome);
                homeButton.setVisibility(View.GONE);
            JSONObject jobObject =encodeData(setting);
            sendDataToServer(jobObject);

        }
    }

    } */
}
package com.PandG.app.android.activities;
导入java.io.BufferedReader;
导入java.io.InputStream;
导入java.io.InputStreamReader;
导入java.util.ArrayList;
导入java.util.List;
导入org.apache.http.HttpResponse;
导入org.apache.http.NameValuePair;
导入org.apache.http.client.HttpClient;
导入org.apache.http.client.entity.UrlEncodedFormEntity;
导入org.apache.http.client.methods.HttpPost;
导入org.apache.http.impl.client.DefaultHttpClient;
导入org.apache.http.message.BasicNameValuePair;
导入org.apache.http.params.HttpConnectionParams;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
导入android.content.Intent;
导入android.os.Bundle;
导入android.text.Html;
导入android.util.Log;
导入android.view.view;
导入android.view.Window;
导入android.widget.Button;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.PandG.app.android.R;
导入com.PandG.app.android.dataAccess.SettingsDBAccess;
导入com.PandG.app.android.entity.Job;
导入com.PandG.app.android.entity.Settings;
导入com.PandG.app.android.services.JobsManager;
导入com.lib.android.Utils.Utils;
导入com.lib.android.activity.BaseActivity;
导入com.lib.android.dataAccess.DatabaseManager;
公共类JobCheckoutActivity扩展了BaseActivity{
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setViewContent();
}
私有void setViewContent(){
设置设置=getSettings();
requestWindowFeature(Window.FEATURE\u自定义\u标题);
setContentView(R.layout.job\u签出);
getWindow().setFeatureInt(Window.FEATURE\u CUSTOM\u TITLE,R.layout.customtitle);
//新建DataProcess().execute(空);
TextView text1=(TextView)findViewById(R.id.checkoutmessage);
text1.setText(“处理作业车…”);
如果(设置!=null){
TextView text2=(TextView)findViewById(R.id.checkoutheading);
text2.setVisibility(View.GONE);
按钮homeButton=(按钮)findViewById(R.id.gohome);
homeButton.setVisibility(View.GONE);
JSONObject jobObject=encodeData(设置);
sendDataToServer(作业对象);
} 
}
私有void sendDataToServer(JSONObject jobObject){
TextView text1=(TextView)findViewById(R.id.checkoutmessage);
text1.setText(“处理作业车…”);
HttpClient=new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(),10000);//超时
//极限
HttpResponse响应;
试一试{
HttpPost=newhttppost(Utils.getpostrl());
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“orderparameters”),
jobObject.toString());
Log.i(“作业顺序”,jobObject.toString());
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
响应=client.execute(post);
checkResponseFromServer(响应);
ClearCart();
}捕获(例外e){
Log.w(“错误”,“连接失败”);
Toast.makeText(这是“由于连接错误而未下订单”,
吐司长度(长);
e、 printStackTrace();
}
}
私有void ClearCart(){
JobsManager.JobsCartList.clear();
}
专用void checkResponseFromServer(HttpResponse响应){
试一试{
if(响应!=null){
InputStream in=response.getEntity().getContent();
BufferedReader reader=新的BufferedReader(
新的InputStreamReader(in);
弦线;
StringBuffer=新的StringBuffer();
而((line=reader.readLine())!=null){
buffer.append(行);
}
in.close();
JSONObject jsonResponse=新的JSONObject(buffer.toString());
Log.i(“Status”,jsonResponse.getString(“Status”);
Log.i(“Status”,jsonResponse.getString(“message”);
Log.i(“Status”,jsonResponse.getString(“debug”);
TextView text1=(TextView)findViewById(R.id.checkoutheading);
text1.setVisibility(View.VISIBLE);
TextView text=(TextView)findViewById(R.id.checkoutmessage);
if(jsonResponse.getString(“status”).equals(“suc”)){
text.setText(Html.fromHtml(getString(R.string.checkout_body1));
}否则
text.setText(jsonResponse.getString(“消息”)
+getString(“调试”);
}
}捕获(例外情况除外){
}
}
私有JSONObject encodeData(设置){
JSONObject jobObject=新的JSONObject();
试一试{
JSONObject jobject=新的JSONObject();
put(“name”,setting.getName());
jobject.put(“email”,setting.getEmail());
jobject.put(“phone”,setting.getPhone());
jobject.put(“school”,setting.getSchool());
jobject.put(“major”,setting.getMajor());
jobObject.put(“客户”,jobject);
JSONArray jobsarray=新的JSONArray();
for(职务:JobsM)
  @Override
protected void onPreExecute() 
TextView.setText("Beginning HTTP-work..Please wait");
{
@Override
protected void onPostExecute(Void v) {
TextView.setText("Done..SUCCESS!");
}