Я получаю свои данные в RecyclerView из веб-службы в асинхронной задаче.
Я запускаю асинхронную задачу из своей основной темы. В RecyclerView есть список. Список должен быть заполнен, но обзор переработчика кажется пустым и ничего не показывает. Когда я открываю приложение в режиме отладки, оно показывает значения. Кто-нибудь знает, как я могу это исправить, я перепробовал все, что мог придумать.
из моего onCreate:
var Recycleview = findViewById<RecyclerView>(R.id.Recycleview)
Recycleview.layoutManager = LinearLayoutManager(this)
Recycleview.adapter = listadapter(HaltestellenEingabe_dummy, this)
AsyncTaskAlleHaltestellen().execute();
в Oncreate - мой onItemClickListener (который обрабатывает Gridlayout)
ItemClickSupport.addTo(Recycleview)
//Onclick listener if RecyclerView is touched
.setOnItemClickListener { recyclerView, position, v ->
var i = 0
Recycleviewchanged = true
while (Haltestellen[i] !=
HaltestellenEingabe_dummy[position]) {
i++
}
println("i =" + i)
HaltestellenID = StationID[i]
AsyncTaskStations().execute();
Recycleview.layoutManager = GridLayoutManager(this, 2)
//makes 3 columns for departion time, line number and the destination
val glm = GridLayoutManager(this, 12)
glm.spanSizeLookup = object :
GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
if (position % 2 == 0) {
return 4
//width of the departion time 1/3
} else {
return 8
//width of the Linenumber 1/6
}
}
}
Recycleview.setLayoutManager(glm)
AbfahrtsmonitorInhalt.add("test")
Recycleview.adapter = listadapter(AbfahrtsmonitorInhalt,
this) //changes Adapter to write the desired content
Recycleview.adapter.notifyDataSetChanged()
}
Asynctask: AsyncTaskStations:
inner class AsyncTaskStations : AsyncTask<String, String, String>() {
override fun doInBackground(vararg p0: String?): String {
webservices.get_Haltestelle_Abfahrten(HaltestellenID)
if(webservices.AbfahrtsmonitorInhalt.size>1)
AbfahrtsmonitorInhalt.clear()
AbfahrtsmonitorInhalt=webservices.AbfahrtsmonitorInhalt
time.post(updateview);
return ""
}
}
AsynctaskHaltestellen:
inner class AsyncTaskAlleHaltestellen : AsyncTask<String, String, String>()
{
override fun doInBackground(vararg p0: String?): String {
webservices.get_Haltestellen()
Haltestellen = webservices.Haltestellen
HaltestellenEingabe = webservices.HaltestellenEingabe
HaltestellenEingabe_dummy = webservices.HaltestellenEingabe_dummy
haltestellen_name = webservices.haltestellen_name
haltestellen_lat = webservices.haltestellen_lat
haltestellen_lon=webservices.haltestellen_lon
StationID = webservices.StationID
return ""
}
}
my Timer Handler () Он открывается каждые 1000 миллисекунд, чтобы показать Recyclerview. Но когда он открывается, он просто показывает пустой RecyclerView. Когда я останавливаюсь здесь в режиме отладчика, тогда он имеет значение и актуализируется.
private val updateview = object : Runnable {
override fun run() {
println("timer")
Recycleview.adapter.notifyDataSetChanged() //draws the route on maps
time.postDelayed(this, 1000)
}
}
мой Listadapter, в котором есть часть, где он пишет специальный текст жирным шрифтом.
class listadapter(val items : ArrayList<String>, val context: Context) : RecyclerView.Adapter<ViewHolder>() {
// Gets the number of animals in the list
override fun getItemCount(): Int {
return items.size
}
// Inflates the item views
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(context).inflate(R.layout.listviewfile, parent, false))
}
// Binds each Item in the ArrayList to a view
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
if(Abfahrtsmonitor.Recycleviewchanged==false) {
holder?.haltestellenliste?.text = SpannableStringBuilder(items[position]).apply {
setSpan(StyleSpan(Typeface.BOLD), 0, Abfahrtsmonitor.Searchlength, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
}
else {
holder?.haltestellenliste?.text = items.get(position)
}
}
}
class ViewHolder (view: View) : RecyclerView.ViewHolder(view) {
// Holds the TextView that will add each stop to
val haltestellenliste = view.aufzaehlunghaltestellen
}