• 7
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I made a simple app in the Android Studio. I took two TextViews and one Button in XML layout file. Both textview and Button are showing in the preview but in the Build Apk there is only Button Showing. It doesn't giving any error. I don't know what is the problem I tried all the possible ways to fix it but didn't get anything.

activity_home XML code

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <EditText android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:hint="mnail"
              android:id="@+id/editText"/>

    <EditText
            android:id="@+id/textViewSendEmail"
            android:layout_width="344dp"
            android:layout_height="44dp"
            android:hint="Email"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"/>
    <EditText
            android:id="@+id/textViewSendPassword"
            android:layout_width="344dp"
            android:layout_height="44dp"
            android:hint="Password"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:layout_below="@+id/textViewSendEmail"/>

    <Button
            android:id="@+id/sendButton"
            android:layout_width="344dp"
            android:layout_height="44dp"
            android:text="send"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="40dp"
            android:layout_below="@+id/textViewSendPassword"/>

</LinearLayout>

MainActivity code

package com.kotlinintent

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_home.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)

        var email_user = textViewSendEmail.text
        var password_user = textViewSendPassword.text

        sendButton.setOnClickListener {
            intent = Intent(this, SecondActvity::class.java)
            intent.putExtra("email", email_user)
            intent.putExtra("password", password_user)
            startActivity(intent)
        }
    }
}

SecondActivity

package com.kotlinintent

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_second.*

class SecondActvity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)


        var bundle : Bundle? = intent.extras
        var emailData = bundle!!.getString("email")
        var passwordData = bundle.getString("password")

        textViewEmail.text = emailData
        textViewPassword.text = passwordData
    }
}

Second Activity 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:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".SecondActvity">

    <TextView
            android:id="@+id/textViewEmail"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:text="Email"/>
    <TextView
            android:id="@+id/textViewPassword"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:text="Password"
            android:layout_marginTop="40dp"
            />

    <Button
            android:id="@+id/getButton"
            android:layout_width="match_parent"
            android:layout_height="44dp"
            android:text="get"
            android:layout_marginTop="40dp"
            />
</LinearLayout>

Instead of these lines

var email_user = textViewSendEmail.text
var password_user = textViewSendPassword.text

Use this

var email_user = textViewSendEmail.text.toString()
var password_user = textViewSendPassword.text.toString()

And also you must call these lines in onclick so your code must like this

 sendButton.setOnClickListener {
        var email_user = textViewSendEmail.text.toString()
        var password_user = textViewSendPassword.text.toString()
        intent = Intent(this, SecondActvity::class.java)
        intent.putExtra("email", email_user)
        intent.putExtra("password", password_user)
        startActivity(intent)
    }

And i suggest that use wrap_content instead of static size (44dp) for height

  • 1
Reply Report
    • it works.. thanks @Radesh and thanks all of you guys the problem was i made objects of textview outside of onclick method. but don't why that object matter because these textviews are static.. anyway thank you
      • 1
    • @PankajTungaria when you call that in you get current text of EditText, so when call in onCreate() it's still null and when you call it in btn click it have some text

Your issue in the way how you put extras. In MainActivity you put your data as extras for intent. But in SecondActivity you try to get data from intent's bundle.

Change this

var bundle : Bundle? = intent.extras
var emailData = bundle!!.getString("email")
var passwordData = bundle.getString("password")

for this

var emailData = intent.getStringExtra("email")
var passwordData = intent.getStringExtra("password")`

Or you can put data into Bundle in MainActivity, then put this Bundle into intent. And then get data, as you do with your current solution.

  • 0
Reply Report
    • They should be visible. Try not to set text for them from activity, leave only text which you set in xml through text parameter.
    • I tried it but nothing has changed. Exactly problem is "Xml textview not showing in build apk file i thing static layout and views always shows without making objects".