Home > OS >  Expendable Floating Button redirecting to another Activity
Expendable Floating Button redirecting to another Activity

Time:11-10

  addFAB.setOnClickListener{
//            val intent = Intent(this, FloatingActionButton::class.java)
//            startActivity(intent)
            if (!fabVisible){
                uploadfolder.show()
                uploadfile.show()
                createFolder.show()

                uploadfolder.visibility = View.VISIBLE
                uploadfile.visibility = View.VISIBLE
                createFolder.visibility = View.VISIBLE

                addFAB.setImageDrawable(resources.getDrawable(R.drawable.ic_close))

                fabVisible = true
            }else   {
                uploadfolder.hide()
                uploadfile.hide()
                createFolder.hide()

                uploadfolder.visibility = View.GONE
                uploadfile.visibility = View.GONE
                createFolder.visibility = View.GONE

                addFAB.setImageDrawable(resources.getDrawable(R.drawable.add))

                fabVisible = false
            }
        }
        uploadfolder.setOnClickListener{
            Toast.makeText(this@MainActivity, "Upload Folder", Toast.LENGTH_LONG).show()
        }

        uploadfile.setOnClickListener{
            Toast.makeText(this@MainActivity, "Upload File...", Toast.LENGTH_LONG).show()
        }
        createFolder.setOnClickListener {
           Toast.makeText(this@MainActivity, "Create new Folder...", Toast.LENGTH_LONG).show()
        }

I am making an App which it required an Expendable Floating Button but it must be redirected on another Activity. I have tried on many ways but its still an error. If anyone can help me it will be very cool.

I have tried a normal call Activity in many ways but I don't have any further idea how to implement a new Intent on on an Extended Floating Button when there is an if and else.

CodePudding user response:

The this is referencing to your onClickListener not to your activity,

val intent = Intent(this, FloatingActionButton::class.java)
startActivity(intent)

so if your activity's name is MySampleActivity your intent should look like this

val intent = Intent(this@MySampleActivity, FloatingActionButton::class.java)
startActivity(intent)
  • Related