ScrollView hides the title bar - java

My small app was working well. When I used ScrollView it overrides the title bar of my App which is JustJava.
content.xml code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16sp"
android:text="Toppings"
android:textAllCaps="true" />
<CheckBox
android:id="#+id/whipped_cream_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whipped Cream"
android:textSize="16sp"
android:layout_marginBottom="16dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16sp"
android:text="Quantity"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/decrease"
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="decrement"
android:text="-" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="0"
android:textColor="#android:color/black" />
<Button
android:id="#+id/increase"
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:text="Order summary"
android:textAllCaps="true"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/order_summary_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:text="$0"
android:textColor="#android:color/black"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16sp"
android:onClick="submitOrder"
android:text="Order" />
</LinearLayout>
</ScrollView>
MainActivity.java
package com.example.bablu.justjava;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.CheckBox;
import android.widget.TextView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import org.w3c.dom.Text;
import java.text.NumberFormat;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
int quantity = 0;
int pricePerCoffee = 5;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
/**
* This method is called when the plus button is clicked.
*/
public void increment(View view) {
quantity = quantity + 1;
displayQuantity(quantity);
}
/**
* This method is called when the minus button is clicked.
*/
public void decrement(View view) {
if (quantity > 0) {
quantity = quantity - 1;
}
displayQuantity(quantity);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
CheckBox whippedCreamCheckbox = (CheckBox)findViewById(R.id.whipped_cream_checkbox);
boolean hasChecked = whippedCreamCheckbox.isChecked();
String priceMessage = createOrderSummary(hasChecked);
displayMessage(priceMessage);
}
private int CalculatePrice(int numberOfCoffees) {
int price = numberOfCoffees * pricePerCoffee;
return price;
}
private String createOrderSummary(boolean hasChecked) {
int getPrice = CalculatePrice(quantity);
String priceMessage = "Name: Bablu Kumar" +
"\nAdd whipped cream? " + hasChecked +
"\nQuantity: " + quantity + "\n" + "Total: $" + getPrice;
priceMessage = priceMessage + "\nThank you!";
return priceMessage;
}
/**
* This method displays the given quantity value on the screen.
*/
private void displayQuantity(int number) {
TextView quantityTextView = (TextView) findViewById(
R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* This method displays the given quantity value on the screen
*/
private void displayMessage(String message) {
TextView OrderSummaryTextView = (TextView) findViewById(R.id.order_summary_text_view);
OrderSummaryTextView.setText(message);
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.bablu.justjava/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.bablu.justjava/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bablu.justjava">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
activity_main.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"
android:fitsSystemWindows="true"
tools:context="com.example.bablu.justjava.MainActivity">
<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_main" />
</android.support.design.widget.CoordinatorLayout>
And here is the picture.
here is the picture
Please help provide a solution to resolve the problem.

Did you tried like this :
<ScrollView
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_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity"
app:layout_behavior="#string/appbar_scrolling_view_behavior" >
Or add android:layout_below="+#id/toolbar" or like android:layout_below="+#id/appbarlayout"

Related

New to Android - Exception - cannot be cast to android.widget.EditText

I'm new to android and am running into an error on a basic app. I am getting the following error,
Caused by: java.lang.ClassCastException: android.widget.RelativeLayout
cannot be cast to android.widget.EditText at
com.example.chris.mytestv1.MainActivity.onCreate(MainActivity.java:39)
Below is the line causing it
numberTxt = (EditText) findViewById(R.id.numberTxt);
In my MainActivity.java i have
package com.example.chris.mytestv1;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
public class MainActivity extends AppCompatActivity {
TextView totalTextView = null;
EditText percentageTxt = null;
EditText numberTxt = null;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
totalTextView = (TextView) findViewById(R.id.TotalTextView);
percentageTxt = (EditText) findViewById(R.id.percentageTxt);
numberTxt = (EditText) findViewById(R.id.numberTxt);
Button calcBtn = (Button) findViewById(R.id.calcBtn);
calcBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
float percentage = Float.parseFloat(percentageTxt.getText().toString());
float dec = percentage / 100;
float total = dec * Float.parseFloat(numberTxt.getText().toString());
totalTextView.setText(Float.toString(total));
}
});
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.chris.mytestv1/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
#Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"Main Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app URL is correct.
Uri.parse("android-app://com.example.chris.mytestv1/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
In my content_main.xml i have -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.chris.mytestv1.MainActivity"
tools:showIn="#layout/activity_main"
android:id="#+id/numberTxt">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:textAlignment="center"
android:textSize="50dp"
android:id="#+id/TotalTextView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What is"
android:id="#+id/textView"
android:layout_below="#+id/TotalTextView"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp"
android:layout_marginBottom="10dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/percentageTxt"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:hint="Enter Percentage"
android:textAlignment="center" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/numberTxt"
android:hint="Enter Number"
android:textAlignment="center"
android:layout_marginTop="48dp"
android:layout_below="#+id/textView3"
android:layout_alignStart="#+id/percentageTxt" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="%"
android:id="#+id/textView2"
android:layout_marginRight="50dp"
android:layout_alignTop="#+id/percentageTxt"
android:layout_toEndOf="#+id/calcBtn"
android:paddingTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Of"
android:id="#+id/textView3"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CALCULATE"
android:id="#+id/calcBtn"
android:layout_marginTop="70dp"
android:textSize="30dp"
android:background="#b91313"
android:textColor="#ffffff"
android:layout_below="#+id/numberTxt"
android:layout_centerHorizontal="true" />
</RelativeLayout>
I've searched for why this error could be occurring however i was unable to find out why.
You have duplication in ids, your RelativeLayout and EditText use the same id:
<RelativeLayout
android:id="#+id/numberTxt">
<EditText
android:id="#+id/numberTxt">
so when android try to findViewById he try to use first which is RelativeLayout not EditText.
I found the error, stupid mistake. I wasn't sure where i should be looking.
<RelativeLayout 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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.chris.mytestv1.MainActivity"
tools:showIn="#layout/activity_main"
android:id="#+id/numberTxt">

Android Full-screen issue

i'm developing android App which is full-screen App,
in the main activity there are 2 buttons
The issue is when i click in the About button the pop-out activity appear
after click on dismiss the title bar appear in the main activity, see the screen capture:
The main activity
After clicking About button and clicking on dismiss
about_popout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="60"
android:background="#android:color/transparent"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="1dp"
android:background="#drawable/about_shape"
android:gravity="center_vertical"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="12pt"
android:textColor="#FFFFFF"
android:text="It&apos;s a PopupWindow" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/common_ic_googleplayservices" />
<Button
android:id="#+id/btn_dismiss"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:text="Dismiss"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
activity_main_menu.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: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="#ff5722"
android:orientation="vertical"
tools:context="com.game.circle.thecirclegame.MainMenu">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="#+id/textView" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="To the Game"
android:id="#+id/startButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20px"
android:layout_marginLeft="100px"
android:layout_marginRight="100px"
android:text="About"/>
</LinearLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.game.circle.thecirclegame">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainMenu">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".GamePanel"></activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
The class MainMenu.java where the title bar appears, after clicking btn_about
package com.game.circle.thecirclegame;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.app.ActionBar.LayoutParams;
public class MainMenu extends AppCompatActivity {
Button btn_startGame, btn_about;
final Context context = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
setContentView(R.layout.activity_main_menu);
addListinerToButtons();
}
public void addListinerToButtons(){
btn_startGame = (Button)findViewById(R.id.startButton);
btn_about = (Button)findViewById(R.id.btn_about);
btn_startGame.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context,GamePanel.class);
startActivity(intent);
}
});
btn_about.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater)
getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.about_popout, null);
final PopupWindow popupWindow = new PopupWindow(popupView, LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
Button btn_dismiss = (Button)popupView.findViewById(R.id.btn_dismiss);
btn_dismiss.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(btn_about, 50, -30);
}
});
}
}
i need to get red of the blue title bar.
You can remove the title bar forever by calling:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
before the setContentView(R.layout.x) in your activity class.
To make the app fullscreen, you can do:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Again, put the above code before the setContentView method.
And make sure, if you are doing this, you should extend your Activity class by Activity and not AppCompatActivity or any other class.
Problem solved.
Because i didn't continue using the popup window,
i create a new activity instead and make the button redirect from main menu to About activity

Invalid session token on SignUp activity Android (Parse backend)

I've been tring for 2 days to get this to work but I couldn't,I keep getting this exception com.parse.ParseRequest$ParseRequestException: invalid session token.
I'm not an experienced android developper and it's my first time with parse so I'd appreciate it if you can post a detailed answer.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.parse.starter"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".ParseApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<meta-data
android:name="com.parse.APPLICATION_ID"
android:value="#string/parse_app_id" />
<meta-data
android:name="com.parse.CLIENT_KEY"
android:value="#string/parse_client_key" />
<activity
android:name=".ParseStarterProjectActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".SignUp"
android:label="#string/title_activity_sign_up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
SignUp.java
package com.parse.starter;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
public class SignUp extends Activity {
private Button sign_up_b;
private TextView email;
private TextView password;
private TextView password_conf;
private TextView firstName;
private TextView lastName;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up);
sign_up_b = (Button)findViewById(R.id.email_sign_up_button);
email = (TextView)findViewById(R.id.email);
password = (TextView)findViewById(R.id.password);
password_conf = (TextView)findViewById(R.id.confirm_password);
firstName = (TextView)findViewById(R.id.first_name);
lastName = (TextView)findViewById(R.id.last_name);
sign_up_b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
attemptSignUp();
}
});
}
private void attemptSignUp(){
// Create the ParseUser
ParseUser user = new ParseUser();
// Set core properties
user.setUsername(email.getText().toString());
user.setPassword(password.getText().toString());
user.setEmail(email.getText().toString());
// Set custom properties
user.put("lName", lastName.getText().toString());
user.put("fName", firstName.getText().toString());
// Invoke signUpInBackground
user.signUpInBackground(new SignUpCallback() {
#Override
public void done(com.parse.ParseException e) {
if (e == null) {
// Hooray! Let them use the app now.
//Intent i = new Intent(getBaseContext(),Splash.class);
//startActivity(i);
} else {
e.printStackTrace();
// Sign up didn't succeed. Look at the ParseException
// to figure out what went wrong
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sign_up, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
signup.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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.parse.starter.SignUp">
<ScrollView android:id="#+id/sign_up_form" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/sign_up_infos" android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="vertical">
<EditText android:id="#+id/first_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_first"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/last_name" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_last"
android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/email" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_email"
android:inputType="textEmailAddress" android:maxLines="1"
android:singleLine="true" />
<EditText android:id="#+id/password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<EditText android:id="#+id/confirm_password" android:layout_width="match_parent"
android:layout_height="wrap_content" android:hint="#string/prompt_confirm_password"
android:inputType="textPassword"
android:maxLines="1" android:singleLine="true" />
<Button android:id="#+id/email_sign_up_button" style="?android:textAppearanceSmall"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:text="#string/action_sign_up"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I've tried the answer in this posts but I kept getting the same exception
com.parse.ParseRequest$ParseRequestException: invalid session token
For future reference all I had to do is uninstall the application from the emulator than run it again and the problem was solved.
You need to logout the user in Login\Signup view controllers.
Try this in viewDidLoad:
ParseUser.getCurrentUser().logOut();

ActivityManager: Warning: Activity not started, its current task has been brought to the front. All the related answer I have read were not fruitful.

I have tried editing the code as it would re-install the application on the emulator but again I'm getting the same error again and again.
It's saying edit source lookup path and showing a button for it.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/images"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter the text here"
android:textColor="#000000"
android:textSize="30dp" />
<EditText
android:id="#+id/textReader"
android:layout_width="match_parent"
android:layout_height="150dp"
android:inputType="textMultiLine"
/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/startReading"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Start reading"
android:textSize="15dp" />
<Button
android:id="#+id/clearBox"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Clear Box"
android:textSize="15dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="7.58" >
</RelativeLayout>
</LinearLayout>
<EditText
android:id="#+id/textDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
That was the main.xml file above.
package a.fr.read;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class FastreaderActivity extends Activity {
/** Called when the activity is first created. */
Button startReading,clearBox;
EditText textReader;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
startReading=(Button)findViewById(R.id.textReader);
clearBox=(Button)findViewById(R.id.textReader);
textReader=(EditText) findViewById(R.id.textReader);
clearBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
textReader.setText("");
}
});
startReading.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
}
}
And this is the java code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="a.fr.read"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/icon"
android:label="#string/app_name" >
<activity
android:name=".FastreaderActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And that was Android manifest file.
First clean your project and refresh that project(In Eclipse- Project-clean)for refresh(go that projectName(ListVeiwdemo) and right click and refresh option will come.)

How can I use the square root of a number that the user enters in an input box, instead of the number itself?

I'm trying to make an Android app, and the feature that I'm working on right now is calculating the square root of a number entered by the user.
How can I take a number that the user enters in a text box, and use the square root of that number in the doCalc part of my program? I'm limiting the number to be an integer between 1 and 20. For example, if the user enters 2 in the input box, I want to use 1.41 in the doCalc method.
Here is my .java code:
package learn.text;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class LearntextActivity extends Activity {
TextView text;
EditText input;
TextView text2;
EditText input2;
TextView text3;
EditText input3;
Button calc;
TextView output;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView) findViewById(R.id.text);
text.setText("Enter the design GPM for Chiller");
input = (EditText) findViewById(R.id.input);
text2 = (TextView) findViewById(R.id.text2);
text2.setText("Enter the Square root of the actual pressure drop across the coil");
input2 = (EditText) findViewById(R.id.input2);
text3 = (TextView) findViewById(R.id.text3);
text3.setText("Enter the design pressure drop of coil");
input3 = (EditText) findViewById(R.id.input3);
calc = (Button) findViewById(R.id.calc);
output = (TextView) findViewById(R.id.output);
}
public void doCalc (View view) {
double mInput = Double.parseDouble(input.getText().toString());
double mInput2 = Double.parseDouble(input2.getText().toString());
double mInput3 = Double.parseDouble(input3.getText().toString());
double mOutput = (mInput*mInput2)/(mInput3);
output.setText("GPM is" + mOutput);
}
}
Here is the .xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<TextView android:layout_height="wrap_content" android:text="" android:layout_width="wrap_content" android:id="#+id/text"></TextView>
<EditText android:layout_height="wrap_content" android:text="" android:layout_width="match_parent" android:id="#+id/input"></EditText>
<TextView android:layout_height="wrap_content" android:text="" android:layout_width="wrap_content" android:id="#+id/text2"></TextView>
<EditText android:layout_height="wrap_content" android:text="" android:layout_width="match_parent" android:id="#+id/input2"></EditText>
<TextView android:layout_height="wrap_content" android:text="" android:layout_width="wrap_content" android:id="#+id/text3"></TextView>
<EditText android:layout_height="wrap_content" android:text="" android:layout_width="match_parent" android:id="#+id/input3"></EditText>
<Button android:layout_height="wrap_content" android:text="Get GPM" android:layout_width="wrap_content" android:id="#+id/calc" android:password="false" android:onClick="doCalc"></Button>
<TextView android:layout_height="wrap_content" android:text="" android:layout_width="wrap_content" android:id="#+id/output"></TextView>
</LinearLayout>
Here is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="learn.text"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="#drawable/ic_launcher" android:label="string/app_name">
android:label="#string/app_name" >
<activity
android:name=".LearntextActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Probably I'm misunderstanding something, but — can't you just change
Double.parseDouble(input2.getText().toString())
to
Math.sqrt(Double.parseDouble(input2.getText().toString()))
? (See http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#sqrt(double) for documentation of Math.sqrt.)

Categories