Skip to content

Instantly share code, notes, and snippets.

@WindSekirun
Last active February 26, 2019 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WindSekirun/4f26929857983e8ff5f61731973639a4 to your computer and use it in GitHub Desktop.
Save WindSekirun/4f26929857983e8ff5f61731973639a4 to your computer and use it in GitHub Desktop.
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