So all I want to do is click the 'Sign up' button on my app and it takes me to the next page. I have made the second page and added a 'setOnclickListener' to the page I want but when I click on the button it takes me to another page that's white. I'm still new to Kotlin. There are no errors popping up that would effect it. Any ideas?
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|center"
android:orientation="vertical"
android:background="#drawable/gradient_background"
android:padding="20dp"
tools:context=".MainActivity">
<!--logo-->
<ImageView
android:id="#+id/logo_image_view"
android:layout_width="117dp"
android:layout_height="116dp"
android:layout_gravity="center"
android:layout_marginTop="80dp"
android:contentDescription="#string/todo"
android:scaleType="centerInside"
android:src="#drawable/logo"
tools:ignore="ImageContrastCheck" />
<!--non interactive log in text-->
<!--EmailAddress enter text-->
<TextView
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/email"
android:textColorHint="#880E4F"
tools:ignore="VisualLintTextFieldSize,TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/password"
android:textColorHint="#4E342E"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<ProgressBar
android:id="#+id/progressbar"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--Login-->
<Button
android:layout_marginTop="40dp"
android:id="#+id/btn_login"
android:text="#string/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--register button-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:id="#+id/button"
android:text="#string/sign_up"
android:onClick="mainActivity"
tools:ignore="UsingOnClickInXml" />
</LinearLayout>
MainActivity.kt
package com.example.gymapp
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
private lateinit var signUpButton: Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
signUpButton = findViewById(R.id.button)
signUpButton.setOnClickListener {
val intent = Intent(this,RegistrationActivity::class.java)
startActivity(intent)
}
}
fun mainActivity(view: View) {}
}
RegistrationActivity.java
package com.example.gymbuddies;
import android.app.Activity;
public class RegistrationActivity extends Activity {
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.Gymapp"
tools:targetApi="31">
<activity android:name=".register" />
<meta-data
android:name="android.app.lib_name"
android:value="" />
<activity
android:name=".Login"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".SignInActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity android:name=".RegistrationActivity"
android:label="Registration">
</activity>
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
</application>
</manifest>
activity_register.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top|center"
android:orientation="vertical"
android:background="#drawable/gradient_background"
android:padding="20dp"
tools:context=".register">
<!--logo-->
<ImageView
android:id="#+id/logo_image_view"
android:layout_width="117dp"
android:layout_height="116dp"
android:src="#drawable/logo"
android:scaleType="centerInside"
android:layout_marginTop="80dp"
android:layout_gravity="center"
/>
<!--non interactive log in text-->
<!--EmailAddress enter text-->
<TextView
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"/>
<!--email-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="center"
android:hint="#string/email"
android:textColorHint="#4527A0"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<!--name-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:gravity="center"
android:id="#+id/name"
android:hint="#string/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<!--dob-->
<!--password-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textfield.TextInputEditText
android:gravity="center"
android:id="#+id/password"
android:hint="#string/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
tools:ignore="VisualLintTextFieldSize" />
</com.google.android.material.textfield.TextInputLayout>
<ProgressBar
android:id="#+id/progressbar"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_marginTop="50dp"
android:id="#+id/btn_register"
android:text="#string/register"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Register.kt
package com.example.gymapp
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.ProgressBar
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputEditText
import com.google.firebase.auth.FirebaseAuth
class Register : AppCompatActivity() {
private lateinit var editTextEmail: TextInputEditText
private lateinit var editTextPassword: TextInputEditText
private lateinit var editName: TextInputEditText
private lateinit var buttonReg: Button
private lateinit var mAuth: FirebaseAuth
private lateinit var progressbar: ProgressBar
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_register)
mAuth = FirebaseAuth.getInstance()
progressbar = findViewById(R.id.progressbar)
editTextEmail = findViewById(R.id.email)
editTextPassword = findViewById(R.id.password)
editName = findViewById(R.id.name)
buttonReg = findViewById(R.id.btn_register)
buttonReg.setOnClickListener {
progressbar.visibility = View.VISIBLE
val email = editTextEmail.text.toString()
val password = editTextPassword.text.toString()
editName.text.toString()
// handle the button click event
if (email.isEmpty() || password.isEmpty()) {
Toast.makeText(this, "Wrong email or password", Toast.LENGTH_SHORT).show()
progressbar.visibility = View.GONE
return#setOnClickListener
}
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
progressbar.visibility = View.GONE
if (task.isSuccessful) {
Toast.makeText(baseContext, "Welcome!.",
Toast.LENGTH_SHORT).show()
} else {
// If sign in fails, display a message to the user.
Toast.makeText(baseContext, "Authentication failed.",
Toast.LENGTH_SHORT).show()
}
}
}
}
}
strings.xml
<resources>
<string name="app_name">GymBuddies</string>
<string name="password">Password</string>
<string name="email_address">Email Address</string>
<string name="type_your_name">Type your name</string>
<string name="login">Login</string>
<string name="email">Email</string>
<string name="register">register</string>
<string name="name">Name</string>
<string name="sign_up">Sign up</string>
<string name="todo">TODO</string>
</resources>
I've read through the code numerous times and I can't see anything conflicting.
Related
Im new to kotlin and Im trying to make a navigation bar with a time selector based on NumberPicker, with 2 other empty fragments (for now atleast), but my problem is that if I start an intent the Navigation bar doesnt show, when I dont put it in code (intent) the navigation bar shows up working correctly, what Im doing wrong, am I missing something??
MainActivity.kt
package com.example.helloworld
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.example.helloworld.databinding.ActivityMainBinding
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.bottomNavigationView.setOnItemSelectedListener {
when (it.itemId) {
R.id.first -> replaceFragment(Home())
R.id.second -> replaceFragment(Voices())
R.id.third -> replaceFragment(Settings())
else -> {
}
}
true
}
replaceFragment(Home())
Intent(this, SecondActivity::class.java).also {
startActivity(it)
}
}
private fun replaceFragment(fragment: Fragment) {
val fragmentManager = supportFragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.frameLayout, fragment)
fragmentTransaction.commit()
}
}
SecondActivity.kt
package com.example.helloworld
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_second.*
class SecondActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_second)
numPickerMin2.minValue = 0
numPickerMin2.maxValue = 23
numPickerSec2.minValue = 0
numPickerSec2.maxValue = 59
var min = 0
var sec = 0
var amOrPm = ""
val str = arrayOf<String>("AM", "PM")
numPickerAM2.minValue = 0
numPickerAM2.maxValue = (str.size - 1)
numPickerAM2.displayedValues = str
numPickerMin2.setOnValueChangedListener { numberPicker, i, i2 ->
min = numberPicker.value
}
numPickerSec2.setOnValueChangedListener { numberPicker, i, i2 ->
sec = numberPicker.value
}
numPickerAM2.setOnValueChangedListener { numberPicker, i, i2 ->
val i = numberPicker.value
amOrPm = str[i]
}
btGetValue2.setOnClickListener {
reminderTime2.text = "$min : $sec : $amOrPm"
}
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.helloworld"
android:installLocation="preferExternal"
android:versionCode="1"
android:versionName="0.2">
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="27" />
<application
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:targetApi="31"
android:theme="#style/Theme.HelloWorld">
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="sensorPortrait"
android:label="#string/app_name"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity">
</activity>
</application>
</manifest>
ActivityMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav"/>
</androidx.constraintlayout.widget.ConstraintLayout>
activity_second.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
android:background="#color/BackgroundFirst"
tools:context=".Home">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayout4"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense.ExposedDropdownMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginTop="55dp"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="#+id/guideline3">
<AutoCompleteTextView
android:id="#+id/dropdown_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:text="Choose Alert"/>
</com.google.android.material.textfield.TextInputLayout>
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerMin2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginEnd="23dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toBottomOf="#+id/numPickerSec2"
app:layout_constraintEnd_toStartOf="#+id/numPickerSec2"
app:layout_constraintTop_toTopOf="#+id/numPickerSec2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="12"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerSec2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginTop="37dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="27dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toTopOf="#+id/textInputLayout4"
app:layout_constraintEnd_toStartOf="#+id/numPickerAM2"
app:layout_constraintTop_toBottomOf="#+id/imageView2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="59"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<com.shawnlin.numberpicker.NumberPicker
android:id="#+id/numPickerAM2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_marginStart="56dp"
android:layout_marginEnd="55dp"
android:gravity="center"
android:theme="#style/AppTheme.Picker"
app:layout_constraintBottom_toBottomOf="#+id/numPickerSec2"
app:layout_constraintEnd_toEndOf="#+id/imageView2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="#+id/numPickerSec2"
app:np_dividerColor="#color/black"
app:np_dividerDistance="55dp"
app:np_dividerLength="100dp"
app:np_dividerThickness="3dp"
app:np_formatter=""
app:np_height="180dp"
app:np_max="1"
app:np_min="0"
app:np_selectedTextColor="#color/selected"
app:np_selectedTextSize="60sp"
app:np_textAlign="textAlignCenter"
app:np_textColor="#color/black"
app:np_textSize="40sp"
app:np_typeface="#string/roboto_light"
app:np_value="1"
app:np_wheelItemCount="10"
app:np_width="74dp"
app:np_wrapSelectorWheel="true" />
<Button
android:id="#+id/btGetValue2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="78dp"
android:backgroundTint="#color/selected"
android:baselineAligned="false"
android:text="Get Time"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="#+id/reminderTime2"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2" />
<TextView
android:id="#+id/reminderTime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="63dp"
android:text="Time"
android:textSize="40sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="351dp"
android:layout_height="103dp"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:scaleX="1.5"
android:scaleY="1.5"
app:layout_constraintEnd_toStartOf="#+id/guideline2"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/helloday_logo" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"
/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/guideline3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
</androidx.constraintlayout.widget.ConstraintLayout>
Instead of creating a second activity, I suggest that you create another fragment. Use it in the same way as the other fragments which you currently have in your app.
When I am clicking on the saving button, the drawing is saving in the image format but it is not sharing. Whenever sharing options shown for sharing, clicking on any app resulting displaying a toast, with the message "Sharing failed, please try again."
Only sharing feature is not working, else the app is working fine.
Manifest file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nandini.android.drawdoodle">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.DrawDoodle">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:authorities="com.nandini.android.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/path"/>
</provider>
</application>
</manifest>
path.xml file in xml directory
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path
name="Captured"
path="Android/data/com.nandini.android.drawdoodle/files"/>
</paths>
MainActivity.kt file
package com.nandini.android.drawdoodle
import android.Manifest
import android.app.AlertDialog
import android.app.Dialog
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.media.MediaScannerConnection
import android.os.Bundle
import android.provider.MediaStore
import android.view.View
import android.widget.*
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import androidx.core.view.get
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
class MainActivity : AppCompatActivity() {
private var drawingView:DrawingClass?=null
private var brush_btn:ImageButton?=null
private var mCurrentPaintBtn:ImageButton?=null
private var picture_btn : ImageButton?=null
private var undo_btn:ImageButton?=null
private var save_btn:ImageButton?=null
private var customProgressDialog:Dialog?=null
val openGalleryLauncher:ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
result->
if(result.resultCode== RESULT_OK && result.data!=null){
var imageBackground:ImageView=findViewById(R.id.iv_background)
imageBackground.setImageURI(result.data?.data)
}
}
val requestPermission: ActivityResultLauncher<Array<String>> = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions())
{
permissions->
permissions.entries.forEach{
val permissionName=it.key
val isGranted=it.value
if(isGranted){
Toast.makeText(this,"Permission Granted",Toast.LENGTH_LONG).show()
val pickIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
openGalleryLauncher.launch(pickIntent)
}
else{
if(permissionName== Manifest.permission.READ_EXTERNAL_STORAGE){
Toast.makeText(this,"Permission denied.",Toast.LENGTH_LONG).show()
}}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
drawingView=findViewById(R.id.drawingId)
picture_btn=findViewById(R.id.picture_btn)
undo_btn=findViewById(R.id.undo_btn)
save_btn=findViewById(R.id.save_btn)
val colour_linear_layout=findViewById<LinearLayout>(R.id.colour_linear_layout)
mCurrentPaintBtn=colour_linear_layout[1] as ImageButton
mCurrentPaintBtn!!.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.pallete_selected))
brush_btn=findViewById(R.id.brush_btn)
brush_btn?.setOnClickListener{
showBrushSizeDialog()
}
picture_btn?.setOnClickListener{
requestStoragePermission()
}
undo_btn?.setOnClickListener{
drawingView?.onUndo()
}
save_btn?.setOnClickListener{
if(isStorageAllowed()){
lifecycleScope.launch {
val flDrawingView:FrameLayout=findViewById(R.id.drawing_frame_layout)
saveBitmapFile(getBitmapFromView(flDrawingView))
}
}
}
}
fun showBrushSizeDialog(){
val BrushSizeDialog=Dialog(this)
BrushSizeDialog.setContentView(R.layout.dialog_brush_size)
BrushSizeDialog.setTitle("Brush Size")
val smallBtn:ImageButton=BrushSizeDialog.findViewById(R.id.small_brush)
smallBtn.setOnClickListener{
drawingView?.setSizeForBrush(10.toFloat())
BrushSizeDialog.dismiss()
}
val mediumBtn:ImageButton=BrushSizeDialog.findViewById(R.id.medium_brush)
mediumBtn.setOnClickListener{
drawingView?.setSizeForBrush(20.toFloat())
BrushSizeDialog.dismiss()
}
val LargeBtn:ImageButton=BrushSizeDialog.findViewById(R.id.large_brush)
LargeBtn.setOnClickListener{
drawingView?.setSizeForBrush(30.toFloat())
BrushSizeDialog.dismiss()
}
BrushSizeDialog.show()
}
fun paintClicked(view: View){
if(view!==mCurrentPaintBtn){
val imageButton=view as ImageButton
val colorTag=imageButton.tag.toString()
drawingView?.setColor(colorTag)
imageButton.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.pallete_selected))
mCurrentPaintBtn?.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.pallete))
mCurrentPaintBtn=view
}
}
fun isStorageAllowed():Boolean{
showProgressDialog()
val result=ContextCompat.checkSelfPermission(this,Manifest.permission.READ_EXTERNAL_STORAGE)
return result==PackageManager.PERMISSION_GRANTED
}
fun requestStoragePermission(){
if(ActivityCompat.shouldShowRequestPermissionRationale(this,Manifest.permission.READ_EXTERNAL_STORAGE)){
showRationaleDialog("Draw Doodle","Draw Doodle requires access to External Storage.")
}else{
requestPermission.launch(arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE))
}
}
fun showRationaleDialog(
title : String,
message: String
){
val builder:AlertDialog.Builder=AlertDialog.Builder(this)
builder.setTitle(title)
.setMessage(message).setPositiveButton("Cancel"){dialog,_->dialog.dismiss()}
builder.create().show()
}
private fun getBitmapFromView(view:View): Bitmap? {
val returnedBitmap=Bitmap.createBitmap(view.width,view.height,Bitmap.Config.ARGB_8888)
val canvas=Canvas(returnedBitmap)
val bgDrawable=view.background
if(bgDrawable !=null){
bgDrawable.draw(canvas)
}else{
canvas.drawColor(Color.WHITE)
}
view.draw(canvas)
return returnedBitmap
}
private suspend fun saveBitmapFile(mBitmap: Bitmap?):String{
var result =""
withContext(Dispatchers.IO){
if(mBitmap !=null){
try {
val bytes=ByteArrayOutputStream()
mBitmap.compress(Bitmap.CompressFormat.PNG,90,bytes)
val f = File(externalCacheDir?.absoluteFile?.toString()+ File.separator+"Draw_Doodle"+System.currentTimeMillis()/1000+".png")
val fo=FileOutputStream(f)
fo.write(bytes.toByteArray())
fo.close()
result=f.absolutePath
runOnUiThread{
cancelProgressDialog()
if(result.isNotEmpty()){
Toast.makeText(this#MainActivity,"File saved successfully : $result",Toast.LENGTH_LONG).show()
shareImage(result)
}else{
Toast.makeText(this#MainActivity,"Something went wrong.",Toast.LENGTH_LONG).show()
}
}
}
catch (e:Exception){
result=""
e.printStackTrace()
}
}
}
return result
}
private fun showProgressDialog(){
customProgressDialog=Dialog(this#MainActivity)
customProgressDialog?.setContentView(R.layout.dialog_custom_progress)
customProgressDialog?.show()
}
private fun cancelProgressDialog(){
if(customProgressDialog !=null){
customProgressDialog?.dismiss()
customProgressDialog=null
}
}
private fun shareImage(result:String){
MediaScannerConnection.scanFile(this, arrayOf(result),null){
path,uri->
val shareIntent=Intent()
shareIntent.action=Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM,uri)
shareIntent.type="image/png"
startActivity(Intent.createChooser(shareIntent,"Share"))
}
}
}
activity_main.xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/drawing_frame_layout"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="5dp"
android:padding="1dp"
android:background="#drawable/drawing_background"
app:layout_constraintBottom_toTopOf="#id/colour_linear_layout"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/img2"
android:scaleType="centerCrop"/>
<com.nandini.android.drawdoodle.DrawingClass
android:id="#+id/drawingId"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80ffffff"
/>
</FrameLayout>
<LinearLayout
android:id="#+id/action_btns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="#id/colour_linear_layout"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" >
<ImageButton
android:id="#+id/undo_btn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
android:src="#drawable/img4" />
<ImageButton
android:id="#+id/brush_btn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
android:src="#drawable/p1" />
<ImageButton
android:id="#+id/picture_btn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
android:src="#drawable/img3" />
<ImageButton
android:id="#+id/save_btn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="5dp"
android:foregroundGravity="center_horizontal"
android:scaleType="fitXY"
android:src="#drawable/img5" />
</LinearLayout>
<LinearLayout
android:id="#+id/colour_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
app:layout_constraintTop_toBottomOf="#id/drawing_frame_layout"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="#id/action_btns">
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:onClick="paintClicked"
android:scaleType="fitXY"
android:background="#color/yellow"
android:tag="#color/yellow"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/pink"
android:onClick="paintClicked"
android:tag="#color/pink"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/green"
android:onClick="paintClicked"
android:tag="#color/green"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/red"
android:onClick="paintClicked"
android:tag="#color/red"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/blue"
android:onClick="paintClicked"
android:tag="#color/blue"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/skin"
android:onClick="paintClicked"
android:tag="#color/skin"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/orange"
android:onClick="paintClicked"
android:tag="#color/orange"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/purple"
android:onClick="paintClicked"
android:tag="#color/purple"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/dark_cyan"
android:tag="#color/dark_cyan"
android:onClick="paintClicked"
android:src="#drawable/pallete" />
<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_margin="2dp"
android:scaleType="fitXY"
android:background="#color/black"
android:onClick="paintClicked"
android:tag="#color/black"
android:src="#drawable/pallete" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
For some odd reason setContentView() is not calling my LoginActivity class. It displays the layout but doesn't read the context? I added a button and the onclicklistener and it isn't being called. Only the layout is being displayed.
This is quite bizarre I've seen to of done every single thing but the LoginActivity is being called? Is it because of the nested layout?
LoginActivity
public class LoginActivity extends BaseActivity implements View.OnClickListener {
#BindView(R.id.button_signin)
Button button_signin;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
//button_login.setOnClickListener(this);
button_signin.setOnClickListener(this);
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button_signin:
Toast.makeText(this, "test321", Toast.LENGTH_SHORT).show();
break;
}
}
}
BaseActivity
public class BaseActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ghostWhiteColor"
android:orientation="vertical"
android:context="test.testing.core.BaseActivity"
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/f_roboto_bold"
android:textColor="#color/holo_blue_light"
android:gravity="center"
android:paddingTop="140dp"
android:textSize="50sp"
android:text="#string/brandingtext" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="200dp">
<android.support.design.widget.TextInputLayout
android:id="#+id/input_login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/login_username"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="text"
android:backgroundTint="#color/ghostWhiteColor"
android:hint="#string/hint_name"
android:singleLine="true"
android:textColor="#color/myBlack"
android:textColorHighlight="#color/antiqueWhiteColor"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/input_login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/login_password"
android:layout_width="285dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:inputType="textPassword"
android:backgroundTint="#color/ghostWhiteColor"
android:hint="#string/hint_name"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
<Button
android:id="#+id/button_signin"
android:layout_width="125dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:background="#drawable/blue_oval"
android:text="#string/btn_login"
android:textColor="#color/ghostWhiteColor" />
<TextView
android:id="#+id/label_register"
android:layout_width="match_parent"
android:layout_height="60dp"
android:fontFamily="#font/f_roboto_lightitalic"
android:gravity="center"
android:text="hello321"
android:textColor="#color/myBlack"
android:textSize="#dimen/fui_heading_padding_bottom" />
</LinearLayout>
</RelativeLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.luxx.market.propg.luxx">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".BaseActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".core.activities.LoginActivity">
</activity>
<activity android:name=".core.activities.RegisterActivity">
</activity>
</application>
</manifest>
You are starting with BaseActivity which is incorrect, baseactivity should be an abstract class.
Put this inside your loginactivity and remove it from the baseactivity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This question already has answers here:
Can not find a View with findViewById()
(4 answers)
Unfortunately MyApp has stopped. How can I solve this?
(23 answers)
What is a stack trace, and how can I use it to debug my application errors?
(7 answers)
Closed 5 years ago.
I'm trying to write a messaging application, but when I start it, it crashes, and I do not get an error message, so I have no clue why.
Launch Activity:
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.*;
public class ConnectActivity extends AppCompatActivity {
private Client client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final EditText txtServerAddress = (EditText) findViewById(R.id.edit_text_server_address);
final EditText txtPortNumber = (EditText) findViewById(R.id.edit_text_port_number);
final EditText txtUsername = (EditText) findViewById(R.id.edit_text_username);
final Button btnLogIn = (Button) findViewById(R.id.button_log_in);
btnLogIn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String username = txtUsername.getText().toString();
if(username.length() == 0)
return;
String portNumber = txtPortNumber.getText().toString();
if(portNumber.length() == 0)
return;
String serverAddress = txtServerAddress.getText().toString();
if(serverAddress.length() == 0)
return;
int port = 0;
try
{
port = Integer.parseInt(portNumber);
}
catch(Exception en)
{
return;
}
ClientActivity clientActivity = new ClientActivity(client);
client = new Client(serverAddress, port, username, clientActivity);
if(!client.start())
return;
Intent intent = new Intent(ConnectActivity.this, ClientActivity.class);
startActivity(intent);
}
});
setContentView(R.layout.activity_connect);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
Launch Content xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity"
tools:showIn="#layout/activity_connect">
<TextView
android:id="#+id/text_view_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/server_address"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text_view_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/port_number"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_server_address" />
<TextView
android:id="#+id/text_view_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="#string/username"
android:textColor="#android:color/black"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edit_text_port_number" />
<EditText
android:id="#+id/edit_text_server_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName|numberDecimal"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_server_address" />
<EditText
android:id="#+id/edit_text_port_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="number"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_port_number" />
<EditText
android:id="#+id/edit_text_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#+id/text_view_username" />
<Button
android:id="#+id/button_log_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:text="#string/log_in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Launch Activity xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.liftedstarfish.lifte.gpschat0_2.ConnectActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_connect" />
</android.support.design.widget.CoordinatorLayout>
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.liftedstarfish.lifte.gpschat0_2">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".ClientActivity"
android:label="#string/title_activity_client"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".ConnectActivity"
android:label="#string/title_activity_connect"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
As far as I can tell, I've done everything correctly, but the application is still crashes. I've tried cleaning the application and rebuilding it, but that did not help.
I'm implementing an Android app for guitar chord recognition. My first layout xml is fine and it's updated, but when I click on login button it goes to next page and didn't show anything on it.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background"
tools:context="com.example.guitarchordrecognition.MainActivity" >
<EditText
android:id="#+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:ems="10"
android:hint="#string/user" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/user"
android:layout_below="#+id/user"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="#string/pass"
android:inputType="textPassword" />
<Button
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/password"
android:layout_alignRight="#+id/user"
android:layout_below="#+id/password"
android:layout_marginTop="41dp"
android:text="#string/login"
/>
</lativeLayout>
afterlogin.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp"
android:text="Button 1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_centerVertical="true"
android:text="Button 2" />
</RelativeLayout>`
Mainactivity.java
public class MainActivity extends ActionBarActivity {
Button mybutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mybutton = (Button)this.findViewById(R.id.login);
mybutton.setOnClickListener(new View.OnClickListener() {
private void buttonclick()
{
startActivity(new Intent("com.example.guitarchordrecognition.Afterlogin"));
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.login:
buttonclick();
break;
}
}
});
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.guitarchordrecognition"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Afterlogin"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.guitarchordrecognition.Afterlogin" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I don't know why you use action constructor, but this time
try startActivity(new Intent(MainActivity.this, Afterlogin.class)); instead.