简体   繁体   English

按页面显示内容(Android/Kotlin)

[英]Show content by pages (Android/Kotlin)

I'm trying to write a simple web application, I have a back-end running on Spring and want to do a front-end as an Android app.我正在尝试编写一个简单的 Web 应用程序,我有一个在 Spring 上运行的后端,并且想要将前端作为 Android 应用程序。 So far I can get some list of the information from my server and show it as a text in my main activity.到目前为止,我可以从我的服务器获取一些信息列表,并将其显示为我的主要活动中的文本。 I'm using Kotlin.我正在使用 Kotlin。 So what I want to do now is to parse Json I got into blocks and show them by pages.所以我现在想要做的是将我得到的 Json 解析成块并按页面显示它们。 For example, I get 12 objects, I want to parse them and show 4 on the one page, so there would be 3 pages.例如,我得到 12 个对象,我想解析它们并在一页上显示 4 个,所以会有 3 页。 Here's my code for my Android app so far:到目前为止,这是我的 Android 应用程序代码:

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.constraint.ConstraintLayout
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.android.volley.Request
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val layout = findViewById<ConstraintLayout>(R.id.root)

        val textView = TextView(this)
        textView.layoutParams = ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        val queue = Volley.newRequestQueue(this)
        val url = "http://localhost/get"
        val stringRequest = StringRequest(
            Request.Method.GET, url,
            Response.Listener<String> { response ->
                textView.text = "Response is: ${response}"
            },
            Response.ErrorListener { response -> textView.text = "${response.message}" })
        queue.add(stringRequest)
        layout?.addView(textView)
    }
}

Also in the future I want to add bottom navigation bar, where you can swap between your profile (or authorization), main page and etc If someone knows any good guides on how to build app like this I would appreciate it, because I didn't find something like this, on the official Android page there's too many deprecicated layouts, libraries, but it doesn't even have any example pictures.将来我还想添加底部导航栏,您可以在其中切换您的个人资料(或授权)、主页等如果有人知道有关如何构建这样的应用程序的任何好的指南,我将不胜感激,因为我没有没有找到这样的东西,在Android官方页面上有太多弃用的布局,库,但它甚至没有任何示例图片。

按照从这里一步一步构建底部导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM