So, recently followed this video's instructions on how to make custom ListView: https://www.youtube.com/watch?v=D0or0X12FMM
The program is crashing on startup, its DOA and show's nothing before it crashes.
It's not logging any errors to the console.
Here's my code for all parts shown in video + mainifest:
I have a feeling it's a problem with the manifest. Just based on other posts. Thanks in advance!
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.doubl.my_application">
<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=".ListTest">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_list_test.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"
android:padding="16dp"
tools:context="com.example.doubl.my_application.ListTest">
<ListView
android:id="#+id/list1"
android:layout_width="312dp"
android:layout_height="519dp"
android:layout_alignParentTop="true"/>
</android.support.constraint.ConstraintLayout>
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
android:id="#+id/icon"
android:src="#mipmap/ic_launcher"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:textColor="#33CC33"
android:id="#+id/text1"
android:layout_marginTop="5dp"
android:layout_marginLeft="10dp"
android:text="Medium Text"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text2"
android:layout_marginLeft="10dp"
android:text="TextView"
/>
</LinearLayout>
</LinearLayout>
ListTest.java
package com.example.doubl.my_application;
import android.content.Context;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
public class ListTest extends AppCompatActivity {
ListView list;
String [] titles;
String [] description;
int[] imgs = {R.drawable.facebook, R.drawable.instagram, R.drawable.twitter, R.drawable.google};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_test);
Resources res = getResources();
titles = res.getStringArray(R.array.titles);
description = res.getStringArray(R.array.description);
list = (ListView) findViewById(R.id.list1);
MyAdapter adapter = new MyAdapter(this, titles, imgs, description);
list.setAdapter(adapter);
}
class MyAdapter extends ArrayAdapter<String>{
Context context;
int[] imgss;
String myTitles[];
String myDescription[];
MyAdapter(Context c, String []titles, int[] img, String[]description){
super(c, R.layout.row, R.id.text1, titles);
this.context = c;
this.imgss = img;
this.myDescription = description;
this.myTitles = titles;
}
#Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflater.inflate(R.layout.row,parent,false);
ImageView images = (ImageView) findViewById(R.id.icon);
TextView myTitle = (TextView) findViewById(R.id.text1);
TextView myDescription = (TextView) findViewById(R.id.text2);
images.setImageResource(R.drawable.facebook);
images.setImageResource(imgs[position]);
myTitle.setText(titles[position]);
myDescription.setText(description[position]);
return row;
}
}
}
Just Goto :
Android Studio --> File --> Setting --> Build, execution, deploy --> Instant run.
and disable instant run .
Related
We are having a resource error when we try to run our code.
package com.example.searchtest;
import android.app.Activity;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class GoogleSearchIntentActivity extends Activity {
private EditText editTextInput;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextInput = (EditText) findViewById(R.id.editTextInput);
}
public void onSearchClick(View v)
{
try {
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
String term = editTextInput.getText().toString();
intent.putExtra(SearchManager.QUERY, term);
startActivity(intent);
} catch (Exception e) {
// TODO: handle exception
}
}
}
<?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" android:padding="10dp">
<edittext
android:id="#+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter search text">
<requestfocus>
</requestfocus></edittext>
<button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_gravity="center"
android:onclick="onSearchClick"
android:layout_margintop="10dp">
</button></linearlayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.searchtest">
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<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=".GoogleSearchIntentActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
these are our mainActivity.java, activity_main.xml, and AndroidManifest.xml codes from our app.
The error is within our public class GoogleSearchIntentActivity extends Activity
We are high school students trying to create an image search app for our computer science capstone class, we have been trying to fix this error without success, and our teacher is completely clueless.
Components in your xml file must have a first capitalized letter.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="10dp">
<EditText
android:id="#+id/editTextInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter search text">
<requestFocus>
</requestFocus></EditText>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search"
android:layout_gravity="center"
android:onclick="onSearchClick"
android:layout_margintop="10dp">
</Button></LinearLayout>
i'm new at android studio and i'm developing my first app.
Everything worked fine until i implemented a splashscreen. Indeed, when i run the app, the splashcreen works, but then, it crashes.
The thing is that the splashscreen wasn't the first activity i've created (the main). I've created my app and when i finished it, i added a splashscreen.
Actually when i disable the splashscreen (the activity) and start directly with the previous "activity that appears on launch" (that is the "Menu"), it works fine.
And one weird thing: with the splashscreen enabled, it crashes only with certain devices. It runs perfectly with my Xiaomi Redmi Note 5 and a Galaxy S4 (or the nexus 5X emulator) but not with a Galaxy S3 and S6 .
I tried to replace the timer by a simple setonclicklistener button. But same, when it has to load the Menu, it crashes.
I haven't find similar problems on the forums so here i am !
The manifest:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="#style/AppTheme">
<activity android:name=".Menu"/>
<activity android:name=".restaurant" />
<activity android:name=".courses" />
<activity android:name=".toilettes" />
<activity android:name=".distributeur" />
<activity android:name=".essence" />
<activity android:name=".hopital" />
<activity android:name=".Splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="#android:style/Theme.Translucent" />
</application>
Here is the Splashscreen -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Handler;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Timer;
public class Splashscreen extends AppCompatActivity {
private ImageView daccord;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_splashscreen);
final TextView random = (TextView) findViewById(R.id.random);
final String[] mesphrases = {"S1", "S2",
"S3", "S4", "S5","S6"};
int rando = (int) (Math.random() * 6);
random.setText(mesphrases[rando]);
this.daccord = findViewById(R.id.daccord);
daccord.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otheractivity = new Intent(Splashscreen.this, Menu.class);
startActivity(otheractivity);
finish();
}
});
}
The Splashscreen xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".Splashscreen"
android:weightSum="10"
android:orientation="vertical"
android:background="#drawable/splashscreenfond">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/spashscreenbienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/splashscreenbienvenue"
android:textSize="40sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5">
<ImageView
android:id="#+id/logo"
android:layout_width="249dp"
android:layout_height="217dp"
android:layout_centerInParent="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/nom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/app_name"
android:textSize="30sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.5">
<TextView
android:id="#+id/bonasavoir"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/bonasavoir"
android:textSize="17sp" />
<TextView
android:id="#+id/donnees"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/random"
android:layout_centerHorizontal="true"
android:text="#string/activezgps"
android:textSize="14sp" />
<TextView
android:id="#+id/random"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="13dp"
android:text="Un être humain a besoin d'environ 2000 kcal/jour"
android:textSize="14sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:id="#+id/version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/version" />
<ImageView
android:id="#+id/daccord"
android:layout_width="124dp"
android:layout_height="105dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/daccord" />
</RelativeLayout>
</LinearLayout>
And the Menu -java
package fr.libertyg.messervices;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
public class Menu extends AppCompatActivity {
private ImageView distributeur;
private ImageView restaurant;
private ImageView courses;
private ImageView toilettes;
private ImageView essence;
private ImageView hopital;
AdView mAdView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
setContentView(R.layout.activity_menu);
this.distributeur = findViewById(R.id.distributeur);
distributeur.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), distributeur.class);
startActivity(otherActivity);
}
});
this.restaurant = findViewById(R.id.restaurant);
restaurant.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), restaurant.class);
startActivity(otherActivity);
}
});
this.courses = findViewById(R.id.courses);
courses.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), courses.class);
startActivity(otherActivity);
}
});
this.toilettes = findViewById(R.id.toilettes);
toilettes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), toilettes.class);
startActivity(otherActivity);
}
});
this.essence = findViewById(R.id.essence);
essence.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), essence.class);
startActivity(otherActivity);
}
});
this.hopital = findViewById(R.id.hopital);
hopital.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent otherActivity = new Intent(getApplicationContext(), hopital.class);
startActivity(otherActivity);
}
});
MobileAds.initialize(this, "ca-app-pub-6520930039267956~4038950000");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
}
And the Menu xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#drawable/fond"
android:orientation="vertical"
android:weightSum="10">
<RelativeLayout
android:layout_weight="1.5"
android:layout_width="match_parent"
android:layout_height="0dp">
<TextView
android:id="#+id/bienvenue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/quoi"
android:textColor="#color/blanc"
android:textSize="30sp"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7.6">
<ImageView
android:id="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginStart="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/distributeur" />
<ImageView
android:id="#+id/restaurant"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_gravity="center_horizontal"
android:layout_marginEnd="37dp"
android:layout_marginTop="29dp"
android:src="#drawable/restaurant" />
<ImageView
android:id="#+id/courses"
top="#+id/distributeur"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/distributeur"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:src="#drawable/courses" />
<ImageView
android:id="#+id/toilettes"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/courses"
android:layout_gravity="center_horizontal"
android:src="#drawable/toilettes" />
<ImageView
android:id="#+id/essence"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignParentBottom="true"
android:layout_alignStart="#+id/distributeur"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="28dp"
android:src="#drawable/essence" />
<ImageView
android:id="#+id/hopital"
android:layout_width="140dp"
android:layout_height="130dp"
android:layout_alignStart="#+id/restaurant"
android:layout_alignTop="#+id/essence"
android:layout_gravity="center_horizontal"
android:src="#drawable/hopital" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9">
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-6520930039267956/3068657000" />
</RelativeLayout>
Thanks by advance for helping me.
In your app gradle make sure that libs use the same version, like:
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha1'
You probably don't need all of them.
Make the changes and then click "Sync Now"
Solved it:
I had to add this to the manifest:
android:largeHeap="true"
And it worked fine.
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'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
I am writing an app that will display a menu of juices at a vape shop.
I have the main screen which displays the name and a button that once clicked will send the user to a new screen displaying the menu.
I am having trouble setting up the button click and when i run the app it crashes after the button is clicked
any input would be appreciated!
MainActivity
package com.example.vitoriano_vaz.easybayvapes;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
public class MainActivity extends AppCompatActivity {
public void sendMessage(View view){
Intent intent = new Intent(FromActivity.this, ToActivity.class);
startActivity(intent);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void startJuiceMenu(View view) {
Log.d("MyApp", "button clicked");
}
}
Second activity once the button is clicked
package com.example.vitoriano_vaz.easybayvapes;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import java.util.ArrayList;
public class juiceMenu extends AppCompatActivity {
ArrayList<String> juiceMenu = new ArrayList<String>(50);
private static String VALUE = "myValue";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
juiceMenu.add("#1 Blueberry Bombshell");
juiceMenu.add("#2 Richie Rich");
juiceMenu.add("#3 Chiquita");
juiceMenu.add("#4 Afternoon Delight");
juiceMenu.add("#5 Poppin Otters");
juiceMenu.add("#6 Viva La Sangria");
juiceMenu.add("#7 Okole Maluna");
juiceMenu.add("#8 Carmen Miranda");
juiceMenu.add("#9 Pomalade");
juiceMenu.add("#10 Izual");
juiceMenu.add("#11 Butter Stotch ");
juiceMenu.add("#12 Blue Bulls");
juiceMenu.add("#13 Grape Ape");
juiceMenu.add("#14 Bruce Juice");
juiceMenu.add("#15 Doc Holiday");
juiceMenu.add("#16 Peachy Keen");
juiceMenu.add("#17 Hula");
juiceMenu.add("#18 New York");
juiceMenu.add("#19 Al Gore");
juiceMenu.add("#20 Lux Charms");
juiceMenu.add("#21 Sailor jack");
juiceMenu.add("#22 Get Him to the Greek");
juiceMenu.add("#23 Key We Lie Chi");
juiceMenu.add("#24 Spring Fling");
juiceMenu.add("#25 Gumby");
juiceMenu.add("#26 Chai-Milk");
juiceMenu.add("#27 Mr. Bean");
juiceMenu.add("#28 50 Shades of Orange");
juiceMenu.add("#29 Blue Waffles");
juiceMenu.add("#30 Enigma");
juiceMenu.add("#31 Mr. Freeze");
//juiceMenu.add("#32 New Flavor"); need to update to get newest flavor
}
}
Activity_main
<?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"
tools:context="com.example.vitoriano_vaz.easybayvapes.MainActivity"
android:id="#+id/main_view">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:text="Welcome to East Bay Vapes"
android:textAllCaps="true"
android:textColor="#000000"
android:textSize="20sp"
android:id="#+id/textView" />
<Button
android:id="#+id/juicemenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="sendMessage"
android:text="#string/JuiceMenu"
android:layout_marginTop="42dp"
android:layout_alignParentTop="true" />
</RelativeLayout>
Activity_juice_menu
here i have a LinearLayout for the ArrayList I declared in juicemenu.java class
<?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="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.vitoriano_vaz.easybayvapes.juiceMenu">
<ListView
android:id="#+id/JuiceMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.vitoriano_vaz.easybayvapes">
<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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".juiceMenu"></activity>
</application>
</
The Intent that you are building needs to reference your own Activity classes.
The first parameter is a Context and the second is the Class of the Activity you want to start so it should be the following.
Intent intent = new Intent(this, juiceMenu.class);
Since your question has already been answered, I thought I'd suggest a more efficient means of populating your array to remove that blemish from your code. For example you can use a string-array resource. With that you simply add the values using a single code line. As an example:
String[] juiceArray = getResources().getStringArray(R.array.JuiceTextArray);
The array values themselves are populated in your arrays.xml file (found in values folder) as such:
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation">
<string-array name="JuiceTextArray" tools:ignore="MissingTranslation">
<item name="Juice1">#1 Blueberry Bombshell.</item>
<item name="Juice2">#2 Richie Rich.</item>
[etc., etc.]
</string-array>
</resources>
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.)