Я использую вид переработчика с некоторым текстом редактирования. но я не мог перечислить значения в представлении переработчика, и оно не показывает никаких ошибок, но представление переработчика не показывает ничего. Я могу получить данные, которые мне нужно отобразить из API, но в классе адаптера getItemcount () возвращает 0 размер.
Класс активности
class Activity_addstaff : AppCompatActivity() {
internal var sprefs: SharedPreferences? = null
var token: String = ""
private var layoutManager: RecyclerView.LayoutManager? = null
private var adapter: RecyclerView.Adapter<*>? = null
private var Outnameslist: MutableList<Outletnamelist>? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_addstaff)
try {
sprefs = this!!.getSharedPreferences(
Config.PACKAGE_NAME, Context.MODE_PRIVATE)
token = sprefs!!.getString("token", "No")!!
} catch (e: Exception) {
}
try {
layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
outletnameslistrecycle!!.layoutManager = layoutManager
Outnameslist = ArrayList()
adapter = outletname_adapter(Outnameslist as ArrayList<Outletnamelist>, this)
outletnameslistrecycle!!.adapter = adapter
getoutletlist();
} catch (e: Exception) {
e.printStackTrace()
}
}
private fun getoutletlist() {
Outnameslist!!.clear()
val stringRequest = object : StringRequest(
Request.Method.POST, Config.URL_OUTLET_NAME,
Response.Listener<String> { response ->
try {
val obj = JSONObject(response)
if (!obj.getBoolean("error")) {
val userssListArray = obj.getJSONArray("outletlist")
for (i in 0 until userssListArray.length()) {
var usersObj = userssListArray.getJSONObject(i)
var outlet = Outletnamelist()
outlet.id=usersObj.getInt("outlet_id")
outlet.name=usersObj.getString("outlet_name")
System.out.println("valuefrom api"+outlet.name)
}
adapter!!.notifyDataSetChanged()
} else {
Toast.makeText(this, obj.getString("message"), Toast.LENGTH_LONG).show()
if (obj.getString("message") == "Your login expired please re login") {
val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
}
}
} catch (e: JSONException) {
e.printStackTrace()
}
},
Response.ErrorListener {
Toast.makeText(this, "Network Error Try Again...", Toast.LENGTH_LONG).show()
}) {
@Throws(AuthFailureError::class)
override fun getParams(): Map<String, String> {
val params = HashMap<String, String>()
params["token"] = token
return params
}
}
stringRequest.retryPolicy = DefaultRetryPolicy(
15000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
VolleySingleton.instance?.addToRequestQueue(stringRequest)
}
}
AdapterClass
class outletname_adapter (internal var Outnamelist: List<Outletnamelist>, private val context: Context) : RecyclerView.Adapter<outletname_adapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.lay_outletnamelist, parent, false)
return ViewHolder(v, context, Outnamelist)
return null!!
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
try {
System.out.println("testgjo "+Outnamelist[position])
var OutletList =Outnamelist[position]
holder.outlet_name!!.text=OutletList.name
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun getItemCount(): Int {
return Outnamelist.size
}
inner class ViewHolder(v: View, var context: Context, private val outnamelist: List<Outletnamelist>) : RecyclerView.ViewHolder(v), View.OnClickListener {
var outlet_checkbox: CheckBox? = null
var outlet_name: TextView?=null
var layTop: LinearLayout?= null
init {
itemView.setOnClickListener(this)
try {
outlet_checkbox=v.findViewById<View>(R.id.checkBox) as CheckBox
outlet_name=v.findViewById<View>(R.id.txt_in)as TextView
} catch (e: Exception) {
e.printStackTrace()
}
}
override fun onClick(v: View) {
val position = adapterPosition
}
}
}
XML
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/diagonal_bg"
tools:context=".Activity_addstaff">
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/img_staff"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="30dp"
android:layout_marginTop="137dp"
android:src="@drawable/subadmin"
app:civ_border_color="#ffffff"
app:civ_border_width="2dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:layout_marginTop="250dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:animateLayoutChanges="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/staffname_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/staffname_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_staffname" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/staffaddress_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/staffaddress_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_address" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/staffplace_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/staffplace_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_place" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/staffpin_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/staffpin_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_pin" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:animateLayoutChanges="true">
<android.support.design.widget.TextInputLayout
android:id="@+id/staffmob_text_input"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/staffmob_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_mob"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/lay_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:id="@+id/lay_root2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/outletnameslistrecycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="1dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:orientation="horizontal"
android:padding="20dp">
<Button
android:id="@+id/btneditstaff"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
style="@style/DefaultButton"
android:background="@drawable/btn_border"
android:foreground="?attr/selectableItemBackground"
android:text="Save"
android:textAllCaps="false"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
помогите мне решить эту проблему.