Java 多个截击请求的问题
每当我想根据用户输入执行截击请求时,我必须按两次按钮来获得请求的响应,而不是只单击一次按钮 我使用了wait()函数,但仍然存在相同的问题,应用程序已损坏,而我希望应用程序能够正常工作 这就是我到目前为止所做的:Java 多个截击请求的问题,java,android,android-volley,Java,Android,Android Volley,每当我想根据用户输入执行截击请求时,我必须按两次按钮来获得请求的响应,而不是只单击一次按钮 我使用了wait()函数,但仍然存在相同的问题,应用程序已损坏,而我希望应用程序能够正常工作 这就是我到目前为止所做的: String URL="https://apifootball.com/api/?action=get_countries&APIkey=b4c74bf2fcf3937f783b752649018a42a3b1bde9d5d7c03ff36f61fc06c00c77";
String URL="https://apifootball.com/api/?action=get_countries&APIkey=b4c74bf2fcf3937f783b752649018a42a3b1bde9d5d7c03ff36f61fc06c00c77";
RequestQueue rq= Volley.newRequestQueue(this);
JsonArrayRequest objreq= new JsonArrayRequest(
Request.Method.GET,
URL,
null,
new Response.Listener<JSONArray>()
{
@Override
public void onResponse(JSONArray response) {
try {
Log.e("result:",response.get(0).toString());
JSONObject obj;
for (int count = 0; count < response.length(); count++) {
obj = response.getJSONObject(count);
String name = obj.getString("country_name");
Log.e("Country:",name);
send(name,true);
// Team t=new Team(2,"mki");
//x.insertTeam(t);
//so on
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener(){
@Override
public void onErrorResponse(VolleyError error) {
Log.e("rest response",error.toString());
}
}
);
rq.add(objreq);
btn_send_message.setOnClickListener(new View.OnClickListener() {
ChatModel model;
public void onClick(View v) {
String text = editText.getText().toString();
else if(text.contains("result"))
{
ChatModel model = new ChatModel(text, true); // user send message
list_chat.add(model);
String result="";
String head2Head;
String input[] = text.split(" ");
String[] arr=null ;
DBAdapter dbAdapter=new DBAdapter(x);
try{
result=dbAdapter.getResultfromDB("Bristol City","Reading");
}catch (Exception e)
{
result="error";
}
if(result.equals("error")==true) {
APIAdapter ap = new APIAdapter();
head2Head = ap.getResult("Bristol City", "Reading", "kjkn", getApplicationContext());
finres = head2Head;
Log.e("headto",head2Head);
arr = head2Head.split("\n");
}
model = new ChatModel("First team:"+arr[0]+"\nSecond team:"+arr[1]+"\n"+"Date:"+arr[2], false);
list_chat.add(model);
}
}
stringurl=”https://apifootball.com/api/?action=get_countries&APIkey=b4c74bf2fcf3937f783b752649018a42a3b1bde9d5d7c03ff36f61fc06c00c77";
RequestQueue rq=Volley.newRequestQueue(this);
JsonArrayRequest objreq=新的JsonArrayRequest(
Request.Method.GET,
网址,
无效的
新的Response.Listener()
{
@凌驾
公共void onResponse(JSONArray响应){
试一试{
Log.e(“result:,response.get(0.toString());
JSONObject对象;
对于(int count=0;count
现在我确实理解了你的问题。发生的事情是数据正在慢慢加载。因此,请使用进度条之类的工具,并在Response.Listener
和Response.ErrorListener
中更改其可见性。若要使其正常工作,请移动行rq.add(objreq)
在onClickListener
内部,并在此行之前将进度条的可见性更改为可见
示例
Layout.xml
Example.java
RelativeLayout progressRL;
//内部onCreate()
progressRL=findViewById(R.id.progressRelLayout);
//做你剩下的事
字符串URL=”https://apifootball.com/api/?action=get_countries&APIkey=b4c74bf2fcf3937f783b752649018a42a3b1bde9d5d7c03ff36f61fc06c00c77";
RequestQueue rq=Volley.newRequestQueue(this);
JsonArrayRequest objreq=新的JsonArrayRequest(
Request.Method.GET,
网址,
无效的
新的Response.Listener()
{
@凌驾
公共void onResponse(JSONArray响应){
progressRL.setVisibility(视图已消失);
试一试{
Log.e(“result:,response.get(0.toString());
JSONObject对象;
对于(int count=0;count