Volley是一个适用于Android的Google库,可以更轻松,更快速地进行网络和远程图像加载。
获取 com.android.volley.ServerError
使用 volley 发出 PUT 请求 Log.i("JsonObject 是",finaljsonData.toString()); 输出:- {“stats”:[{“med_id”:1,“med_name”:“晚上”,“start_date”:1476107306168,“end_date”:1476193706168,“坚持”:{“tak...
我正在尝试使用volley从mysql数据库获取数据并将其显示在recycleview中,但我有一个问题recycleview不显示。 这是 order_layout.xml : 我正在尝试使用 volley 从 mysql 数据库获取数据并将其显示在 recycleview 中,但我有一个问题,recycleview 没有显示。 这是 order_layout.xml : <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/cardHolder" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:background="@drawable/order_background" android:padding="8dp"> <LinearLayout android:id="@+id/orderView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:background="@drawable/orderid_background" android:orientation="vertical" android:padding="16dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="Order ID " android:textColor="@color/white" /> <TextView android:id="@+id/orderID" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="6dp" android:text="1" android:textColor="@color/white" android:textSize="18sp" /> </LinearLayout> <LinearLayout android:id="@+id/linear1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="12dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/orderView" app:layout_constraintTop_toTopOf="parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Client Name:" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/clientName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:text="test" android:textColor="@color/black" android:textSize="20sp" /> </LinearLayout> <LinearLayout android:id="@+id/linear2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="12dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/orderView" app:layout_constraintTop_toBottomOf="@+id/linear1"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Order Date:" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/orderDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:text="test" android:textColor="@color/black" android:textSize="20sp" /> </LinearLayout> <LinearLayout android:id="@+id/linear3" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginStart="12dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/orderView" app:layout_constraintTop_toBottomOf="@+id/linear2"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Status:" android:textColor="@color/black" android:textSize="20sp" /> <TextView android:id="@+id/orderStatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginStart="10dp" android:text="test" android:textColor="@color/black" android:textSize="20sp" /> </LinearLayout> </androidx.constraintlayout.widget.ConstraintLayout> activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/RecycleV" android:layout_width="match_parent" android:layout_height="match_parent" tools:itemCount="2" tools:listitem="@layout/order_layout" /> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/addBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_margin="16dp" android:backgroundTint="@color/cardview_dark_background" android:contentDescription="@string/adding_order" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:srcCompat="@drawable/baseline_add_24" app:tint="@color/white" /> </androidx.constraintlayout.widget.ConstraintLayout> </layout> MainActivity.kt package com.example.demo import android.os.Bundle import android.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.LinearLayoutManager import com.android.volley.Request import com.android.volley.toolbox.StringRequest import com.android.volley.toolbox.Volley import com.example.demo.databinding.ActivityMainBinding import org.json.JSONArray import org.json.JSONException class MainActivity : AppCompatActivity() { private val URL = "http://192.168.100.12/demo/Android/v1/getAll.php" lateinit var binding: ActivityMainBinding private lateinit var ordersList: ArrayList<Order> private lateinit var rcvAdapter: CustomAdapter override fun onCreate(savedInstanceState: Bundle?) { binding = ActivityMainBinding.inflate(layoutInflater) super.onCreate(savedInstanceState) setContentView(binding.root) ordersList = ArrayList() rcvAdapter = CustomAdapter(ordersList) binding.RecycleV.layoutManager = LinearLayoutManager(this) binding.RecycleV.setHasFixedSize(true) binding.RecycleV.adapter = rcvAdapter loadData() // binding.rv.apply { // layoutManager = LinearLayoutManager(this@MainActivity) // adapter = rcvAdapter // } // binding.sr.setOnRefreshListener { // loadData() // binding.sr.isRefreshing = false // } // binding.addBtn.setOnClickListener { // val intent = Intent() // } } private fun loadData() { val queue = Volley.newRequestQueue(this) val stringRequest = StringRequest(Request.Method.POST, URL, { response -> try { Log.e("anytext", response) val jsonArray = JSONArray(response) for (i: Int in 0 until jsonArray.length()) { val jsonObject = jsonArray.getJSONObject(i) val order = Order( jsonObject.getInt("ID"), jsonObject.getString("orderDate"), jsonObject.getString("status"), jsonObject.getString("name") ) ordersList.add(order) Log.e("order data", order.toString()) Log.e("array size", ordersList.size.toString()) } } catch (e: JSONException) { e.printStackTrace() } if (response.isEmpty()) { Toast.makeText(this, "There is no orders", Toast.LENGTH_SHORT).show() } }, { error -> Toast.makeText( this, error.message, Toast.LENGTH_LONG ).show() }) queue.add(stringRequest) Log.e("final", "success") } } 自定义适配器.kt package com.example.demo import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView class CustomAdapter( private val ordersList: ArrayList<Order> ) : RecyclerView.Adapter<CustomAdapter.MyViewHolder>() { inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { val id: TextView = itemView.findViewById(R.id.orderID) val clientName: TextView = itemView.findViewById(R.id.clientName) val orderDate: TextView = itemView.findViewById(R.id.orderDate) val orderStatus: TextView = itemView.findViewById(R.id.orderStatus) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.order_layout, parent, false) return MyViewHolder(view) } override fun getItemCount(): Int { return ordersList.size } override fun onBindViewHolder(holder: MyViewHolder, position: Int) { val order = ordersList[position] holder.apply { id.text = order.id.toString() orderStatus.text = order.status orderDate.text = order.orderDate clientName.text = order.clientName } } } 订单.kt package com.example.demo data class Order(val id: Int, val orderDate: String, val status: String, val clientName: String) 我尝试更改 activiy_main.xml 和 order_layout.xml 的布局,但没有任何效果,并且还尝试记录以了解数据是否已获取,我发现它们已被检索 您没有在任何地方更新适配器。 向 ordersList 添加内容后,您需要让 RecyclerView 的适配器知道。 例如: fun update(val newOrdersList: List<Order>) { ordersList.clearAll() ordersList.addAll(newOrdersList) notifyDataSetChanged() // This is deprecated but works - demonstration only } 整个 notifyDatasetChanged 可能会给您带来一个优化 RecyclerView 性能的新兔子洞,但为了给您一个简单的答案,我不会深入讨论它。
嘿,我在volley sql中使用数组获取Json中的数据,但发现错误是数据未在recycler view中加载。我正在获取具有相同 id 的所有行。但数据未加载。我在这里...
如何将 Body 数据发送到 GET 方法请求 Android
像这样,我想将JSON正文请求发送到GET API。 尝试过这个但没有成功: 公共静态无效getQuestionsListApi2(最终字符串requestId,最终字符串时间戳, ...
执行第二次 Volley 请求 Android Studio 时 URL 错误
移动开发新手,请遵循一组视频教程。我在活动开始时执行 JSON 对象请求。我需要执行第二个请求,但这次是使用
限制通过 Business Central 中的 API 调用获取的记录数量
场景: 你好, 我正在使用 volley 库从 Kotlin 中的业务中心 API 获取一些数据,但问题是,JSON 响应大约有 20000 个值或记录,而 JSON 的大小约为...
我创建了一个活动来更新数据。当其他数据(名称、类别或 jumlah)更新时,必须再次添加图像。 @可为空 @覆盖 ...
我实现了 volley 库(实现'com.android.volley:volley:1.1.1')但是当我尝试在 MainActivity 中编写 StringRequest 时它不会导入。 我和经理有同样的问题
我正在使用 ElevenLabs Api 将文本转换为语音,这个 api 主要返回 byte[] 作为音频,我尝试使用 MediaPlayer 和 AudioTrack 播放它但失败了,有没有人如何做到这一点,
如何通过android studio中的volley库解析来自Json的复杂数据?
我想通过 volley 库从 api 获取数据。 我正在通过 Android 中的 Volley 类检索 JSON 对象和 Json Arrray。我知道如何获取请求,但我真的很难解析这个
我想使用 kotlin 流从 rest 端点异步加载多个数据,并将其显示在回收器视图中。数据定义为 ServiceDto、ProductDto、CategoryDto。 ProductDto 有一个
当我从 API 发送数据然后使用 Room 数据库将数据存储回应用程序时,我遇到了一个小问题。我为什么要这样做,因为我正在开发类似电子商务的应用程序,可以将产品存储在...
在 kotlin 中使用 volley 的 Android studio API 集成
我是 android 开发的新手,我在使用我使用 asp.net 开发的简单 rest API 时遇到了一个问题,该 api 工作正常,我已经在 postman 中测试了 api,它也可以正常工作...
使用 Retrofit2 和 Volley 从 JSON 数组获取项目时我没有问题。 但是,我无法从 JSON 对象中获取项目, 像这个 API JSON 代码: { “目的”: { “项目 1”:“...
Android - 意外响应代码 400 - 使用 Volley 将 MP3 发布到 OpenAI Whisper
女士们,先生们,您好, 我有一个 Volley 的小项目。 目前我尝试发布我录制的 MP3 并将我存储在 cacheDir 中。 私有 var audioFile:文件? = 空 文件(cacheDir,“奥迪...
我尝试从 MySQL 表中检索数据到 android 回收器查看我无法根据登录用户检索数据的问题我尝试这个 PHP 代码 我在 POSTMAN 上取得了不错的成绩,但没有运行......
我在从 API 获取图像时遇到问题。当我在 Postman 中观看响应并将其另存为图像时 - 它保存得很好并且是有效图像。但我无法让它在 Java 中工作。 下面是我的 HTTPR...
我正在尝试使用前端的 volley 库和后端的 spring boot 编写一个获取请求。我已经测试了后端并且它工作得很好但是截击的响应是空的,任何想法......
在简单的 xampp mysql 数据库连接应用程序与 java 文件,如 main,数据库助手,登录,注册,产品,productadapter,searchmenu,splash 和 android studio 中的 Utils,出现错误我....
在kotlin中,Recycler视图不显示jason数据。
这是我的主类,我在ArrayList中使用volley添加json数据。Toast显示了json数据,但数组不显示任何数据。我试图解决我的错误,从过去的3天,我也阅读了许多......