Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btn = findViewById<Button>(R.id.button1)
btn.setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
requestSend()
}
})
}
fun requestSend() {
val jsonobj = JSONObject()
jsonobj.put("nim", nim_editText.text)
jsonobj.put("nama", nama_editText.text)
jsonobj.put("address", address_editText.text)
val queue = Volley.newRequestQueue(this)
val url = "http://192.168.100.7/simplecrud/create.php"
val req = JsonObjectRequest(Request.Method.POST,url,jsonobj,
Listener {
Toast.makeText(this@MainActivity, "Success", Toast.LENGTH_SHORT).show()
},
ErrorListener {
Toast.makeText(this@MainActivity, "Error Occured", Toast.LENGTH_SHORT).show()
})
queue.add(req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.