gpt4 book ai didi

java - 从 json 文件加载数据后,android 中的进度条没有停止

转载 作者:行者123 更新时间:2023-12-02 02:24:17 24 4
gpt4 key购买 nike

在尝试了很多次之后没有成功,我正在从数据库中以 json 格式检索数据并在 android 的 recyclerview 中显示。一旦显示数据,进度条就不会停止或不会变得不可见。只有进度条不起作用mainactivity.java

`protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnDatePicker = (Button) findViewById(R.id.btn_date);
MobileProgressBar = (ProgressBar)findViewById(R.id.progressBar);
loadRecyclerViewData();`



`private void loadRecyclerViewData(){

//to fetch data we do string request
StringRequest stringRequest = new StringRequest(Request.Method.GET,
URL_Data,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
//JSONObject jsonObject=new JSONObject(s);
// JSONArray array=jsonObject.getJSONArray("contact");//Array name

//converting the string to json array object

JSONArray array = new JSONArray(response);
//JSONArray arr=array.getJSONArray("Array");

for(int i=0;i< array.length();i++){
//getting product object from json array

JSONObject jsonObjec = array.getJSONObject(i);

ListUser user=new ListUser(
jsonObjec.getString("name"),
jsonObjec.getString("email"),
jsonObjec.getString("contactno"),
jsonObjec.getString("date"),
jsonObjec.getString("time"),
jsonObjec.getString("requirement_type"),
jsonObjec.getString("message")

);

listUsers.add(user);

}



adapter=new MyAdapter(listUsers, getApplicationContext());//data from MyAdapter constructor
recyclerView.setAdapter(adapter);

}

catch (JSONException e) {
e.printStackTrace();
}
}
},

new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {

Toast.makeText(getApplicationContext(), volleyError.getMessage(), Toast.LENGTH_SHORT).show();
}
});

RequestQueue requestQueue= Volley.newRequestQueue(this);

requestQueue.add(stringRequest);
MobileProgressBar.setVisibility(View.GONE);
}`

有人想帮忙

最佳答案

设置适配器后尝试此操作 MobileProgressBar.setVisibility(View.GONE);

 adapter=new MyAdapter(listUsers, getApplicationContext());//data from 
MyAdapter constructorrecyclerView.setAdapter(adapter);
MobileProgressBar.setVisibility(View.GONE);

关于java - 从 json 文件加载数据后,android 中的进度条没有停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48018957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com