I am new to Android development and I have an issue with making Android EditText vertically scroll able. The vertical scrolling of the EditText does not work for me. I followed several posts and resources but none of them worked for me.
I am using the following code sample to enable the vertical scroll ability.
this.detailsEditText.setScroller(new Scroller(this));
this.detailsEditText.setMaxLines(1);
this.detailsEditText.setVerticalScrollBarEnabled(true);
this.detailsEditText.setMovementMethod(new ScrollingMovementMethod());
The following are the activity class and layout resource file, respectively I am using in my app.
CreateAppointmentActivity.java
package lk.iit.appointmentmanagerapp.activities;
import java.sql.Date;
import java.sql.Time;
import lk.iit.appointmentmanagerapp.data.Appointment;
import lk.iit.appointmentmanagerapp.data.DatabaseHandler;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Scroller;
public class CreateAppointmentActivity extends Activity {
private EditText titleEditText;
private EditText timeEditText;
private EditText detailsEditText;
private EditText dateEditText;
private Button saveButton;
private Button resetButton;
private final DatabaseHandler handler = new DatabaseHandler(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_appointment);
this.titleEditText = (EditText)(this.findViewById(R.id.edit_title));
this.timeEditText = (EditText)(this.findViewById(R.id.edit_time));
this.detailsEditText = (EditText)(this.findViewById(R.id.edit_details));
this.dateEditText = (EditText)(this.findViewById(R.id.edit_date));
this.detailsEditText.setScroller(new Scroller(this));
this.detailsEditText.setMaxLines(1);
this.detailsEditText.setVerticalScrollBarEnabled(true);
this.detailsEditText.setMovementMethod(new ScrollingMovementMethod());
SharedPreferences preferences = getSharedPreferences("date_variables", MODE_PRIVATE);
this.dateEditText.setText(preferences.getInt("Year", 0) + "-" + preferences.getInt("Month", 0) + "-" + preferences.getInt("Day", 0));
this.dateEditText.setEnabled(false);
this.saveButton = (Button)(this.findViewById(R.id.save_new_appointment_button));
this.saveButton.setOnClickListener(new View.OnClickListener() {
#SuppressWarnings("deprecation")
#Override
public void onClick(View v) {
String[] dateComponents = dateEditText.getText().toString().split("-");
String[] timeComponents = timeEditText.getText().toString().split(":");
Appointment appointment = new Appointment();
appointment.setAppointment_title(titleEditText.getText().toString());
appointment.setAppointment_date(new Date(Integer.parseInt(dateComponents[0]), Integer.parseInt(dateComponents[1]), Integer.parseInt(dateComponents[2])));
appointment.setAppointment_time(new Time(Integer.parseInt(timeComponents[0]), Integer.parseInt(timeComponents[1]), Integer.parseInt(timeComponents[2])));
appointment.setAppointment_details(detailsEditText.getText().toString());
boolean inserted = handler.addAppointment(appointment);
//
//
}
});
this.resetButton = (Button)(this.findViewById(R.id.reset_button));
this.resetButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
titleEditText.setText("");
timeEditText.setText("");
detailsEditText.setText("");
dateEditText.setText("");
}
});
}
}
activity_create_appointment.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="#color/background"
tools:context="lk.iit.appointmentmanagerapp.activities.CreateAppointmentActivity" >
<TextView
android:id="#+id/create_activity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome_create"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dip"
android:layout_marginBottom="25dip"
android:textSize="18.5sp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/create_activity_title"
android:layout_marginTop="15dip"
android:text="#string/title_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/create_activity_title"
android:layout_marginTop="15dip"
android:layout_toRightOf="#+id/title_textview"
android:layout_marginLeft="30dip"
android:background="#ffffff"
android:ems="10"
android:inputType="text" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/time_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title_textview"
android:layout_marginTop="25dip"
android:text="#string/time_textview_text"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<EditText
android:id="#+id/edit_time"
android:background="#ffffff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/time_textview"
android:layout_below="#+id/edit_title"
android:layout_marginLeft="25dip"
android:layout_marginTop="25dip"
android:ems="10"
android:inputType="time" />
<TextView
android:id="#+id/details_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/time_textview"
android:text="#string/details_textview_text"
android:layout_marginTop="25dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/details_textview"
android:layout_alignBottom="#+id/details_textview"
android:layout_alignLeft="#+id/edit_title"
android:background="#ffffff"
android:ems="10"
android:inputType="text" >
</EditText>
<TextView
android:id="#+id/date_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/details_textview"
android:text="Date"
android:layout_marginTop="25dip"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/edit_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/date_textview"
android:layout_below="#+id/edit_details"
android:background="#ffffff"
android:layout_marginLeft="25dip"
android:layout_marginTop="25dip"
android:ems="10"
android:inputType="date" >
</EditText>
<Button
android:id="#+id/save_new_appointment_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/date_textview"
android:layout_marginTop="15dip"
android:layout_marginBottom="10dip"
android:layout_centerHorizontal="true"
android:text="#string/save_button_text"
android:textAllCaps="false" />
<Button
android:id="#+id/reset_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/save_new_appointment_button"
android:layout_marginTop="2dip"
android:layout_centerHorizontal="true"
android:text="#string/reset_button_text"
android:textAllCaps="false" />
</RelativeLayout>
Please bear with me if I have done any mistakes as I am relatively new to this area of development.
I would be grateful if someone help me out with this issue.
Try this in java code:
EditText dwEdit = (EditText) findViewById(R.id.DwEdit);
dwEdit.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (view.getId() ==R.id.DwEdit) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}
return false;
}
});
And in your xml:
<EditText
android:id="#+id/DwEdit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="10"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:overScrollMode="always"
android:inputType="textCapSentences">
</EditText>
If you wanna scroll editText only in detailEditText then you specify height of editText 50dp or your need and remove inputType="text" from your editText ....it fulfill your need..
and you don't need any code in java relative to that editText..
Related
I have the following code but it changes the button text to empty. I'm basically trying to change the the button's text when it clicked to whatever the user types into the edit text field I have. Everything seems to work, however, when I click on either buttons I have the button's text changes to empty/null and since i'm using wrap content it shrinks the size of the button too.
activity_main.xml
<LinearLayout
android:layout_width="368dp"
android:layout_height="495dp"
android:orientation="vertical"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0000ff"
android:gravity="center"
android:padding="10dp"
android:text="Name: Balkar Rana"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:textColor="#FFFF00"
android:textSize="20dp"
android:textStyle="bold"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:textColor="#FF69B4"
android:text="Username: "
android:textSize="20dp"/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="20dp"
android:id="#+id/username"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:textColor="#63ea1f"
android:text="Password: "
android:textSize="20dp"/>
<EditText
android:inputType="textPassword"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:gravity="left"
android:textColor="#000000"
android:textSize="20dp"
android:id="#+id/password"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="25dp">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:text="Username"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#FF69B4"
android:id="#+id/userButton"
android:onClick="onClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:text="Password"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#63ea1f"
android:id="#+id/passButton"
android:onClick="onClick"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:text="USER-PASS"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#FF69B4"
android:id="#+id/userPassButton"
android:onClick="onClick"/>
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.example.balkarrana.lab2;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText usernameInput = (EditText)findViewById(R.id.username);
final String userText = usernameInput.getText().toString();
final Button userButtonVariable = (Button)findViewById(R.id.userButton);
EditText passwordInput = (EditText)findViewById(R.id.username);
final String passText = passwordInput.getText().toString();
final Button passButtonVariable = (Button)findViewById(R.id.passButton);
final String userPassText = userText + passText;
final Button userPassButtonVariable = (Button)findViewById(R.id.userPassButton);
userButtonVariable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
userButtonVariable.setText(userText);
}
});
passButtonVariable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
passButtonVariable.setText(passText);
}
});
userPassButtonVariable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
userPassButtonVariable.setText(userPassText);
}
});
}
}
You are getting the value of the EditText within your onCreate when the app is first started and they will be blank. You need to get the current value within the onClick and then set it. Here's how I'd do it for the userButton.
...
public class MainActivity extends AppCompatActivity{
EditText usernameInput;
Button userButtonVariable;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usernameInput = (EditText)findViewById(R.id.username);
userButtonVariable = (Button)findViewById(R.id.userButton);
userButtonVariable.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String userText = usernameInput.getText().toString();
userButtonVariable.setText(userText);
}
});
To stop a button changing size don't set the width to be wrap_content.
Try match_parent and then use margins.
<Button
android:layout_width="match_parent"
...
</Button>
I have a simple LinearLayout with several buttons, whos state color/text change based on the state of an underlying service, thats working fine.
However the buttons, are only clickable on the right corner ???
The button allSystemServicesToggleButton which i have included the implementation for in this post and only be clicked on the right side/right corner???
Here is my fragment xml layout & Actual screen shot with “Show Layout bounds” set to true:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:text="All System Services"
android:textColor="#000000"
android:textSize="20sp"
android:layout_weight="1"
android:layout_width="0dp"
android:singleLine="true"
android:onClick="onClick"/>
<Button
android:id="#+id/allSystemServicesToggleButton"
android:layout_height="wrap_content"
android:text="#string/stopped"
android:layout_weight="1"
android:layout_width="0dp"
android:backgroundTint="#color/stoppedServiceColor"
android:enabled="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:text="#string/shutdown_all_services"
android:textColor="#000000"
android:textSize="20sp"
android:layout_weight="1"
android:layout_width="0dp"
android:singleLine="true"
android:onClick="onClick"/>
<Button
android:id="#+id/shutdownAllServicesToggleButton"
android:layout_height="wrap_content"
android:text="#string/shutdown"
android:layout_weight="1"
android:layout_width="0dp"
android:enabled="true"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Networks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textColor="#000000"/>
<View
android:id="#+id/viewServicesDivider1"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#808080"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:text="Bluetooth Service"
android:textColor="#000000"
android:textSize="20sp"
android:singleLine="true"/>
<Button
android:id="#+id/btServicesToggleButton"
android:layout_height="wrap_content"
android:text="#string/stopped"
android:layout_weight="1"
android:layout_width="0dp"
android:backgroundTint="#color/stoppedServiceColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--TODO: get requirements for showing paired devices & pairing devices-->
<TextView
android:id="#+id/textPairedText"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Paired Bluetooth Devices"
android:textColor="#000000"
android:singleLine="true"
android:textSize="20sp"
android:layout_width="0dp"
/>
<TextView
android:id="#+id/textViewNumberOfConnectedDevices"
android:layout_height="wrap_content"
android:text="0"
android:layout_width="0dp"
android:layout_weight="1" />
<Button
android:id="#+id/btDevicesToggleButton"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="2"
android:text="Pair"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:text="MQTT Service"
android:textColor="#000000"
android:textSize="20sp"
android:singleLine="true"/>
<Button
android:id="#+id/MQTTserviceToggleButton"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:backgroundTint="#color/stoppedServiceColor"
android:text="#string/stopped" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Location Services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textColor="#000000"/>
<View
android:id="#+id/viewServicesDivider3"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#808080"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:text="GPS"
android:textColor="#000000"
android:textSize="20sp"
android:singleLine="true"/>
<Button
android:id="#+id/gpsServiceToggleButton"
android:layout_height="wrap_content"
android:text="#string/stopped"
android:layout_weight="1"
android:layout_width="0dp"
android:backgroundTint="#color/stoppedServiceColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:text="Command Services"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="32sp"
android:textColor="#000000"/>
<View
android:id="#+id/viewServicesDivider4"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#808080"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_width="0dp"
android:text="Voice Recognition"
android:textColor="#000000"
android:textSize="20sp"
android:singleLine="true"/>
<Button
android:id="#+id/voiceRecognitionToggleButton"
android:layout_height="wrap_content"
android:text="#string/stopped"
android:layout_weight="1"
android:layout_width="0dp"
android:backgroundTint="#color/stoppedServiceColor"
/>
</LinearLayout>
Relevant fragment java:
package x.core.fragments;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.speech.tts.TextToSpeech;
import android.support.v4.app.Fragment;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import x.core.Application.NgfrApp;
import x.core.R;
import x.core.helpers.Util;
import x.core.services.BluetoothService;
import x.core.services.LocationService;
import x.core.services.MqttBrokerService;
import x.core.services.ServicesStateBroadcastReceiver;
import x.core.services.SpeechRecognitionService;
import x.core.services.UIService;
public class ServicesFragment extends Fragment implements View.OnClickListener {
private static final String TAG = "ServicesFragment";
public static ServicesFragment newInstance() {
return new ServicesFragment();
}
private static Button btServicesToggleButton;
private static Button mqttServicesToggleButton;
private static Button gpsServiceToggleButton;
private static Button voiceServiceToggleButton;
private static Button allServiceToggleButton;
private static String stopped = null;
private static String running = null;
private static int runningColorId, stoppedColorId = -1;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_services, container, false);
btServicesToggleButton = rootView.findViewById(R.id.btServicesToggleButton);
mqttServicesToggleButton = rootView.findViewById(R.id.MQTTserviceToggleButton);
gpsServiceToggleButton = rootView.findViewById(R.id.gpsServiceToggleButton);
voiceServiceToggleButton = rootView.findViewById(R.id.voiceRecognitionToggleButton);
allServiceToggleButton = rootView.findViewById(R.id.allSystemServicesToggleButton);
stopped = getResources().getString(R.string.stopped);
running = getResources().getString(R.string.running);
runningColorId = getResources().getColor(R.color.runningServiceColor);
stoppedColorId = getResources().getColor(R.color.stoppedServiceColor);
allServiceToggleButton.setEnabled(true);
allServiceToggleButton.setClickable(true);
allServiceToggleButton.setOnClickListener(this);
return rootView;
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.allSystemServicesToggleButton:
if (ServicesStateBroadcastReceiver.BT_SERVICE_STATE_VALUE==false || ServicesStateBroadcastReceiver.MQTT_STATE_VALUE==false || ServicesStateBroadcastReceiver.NGFR_GPS_SERVICE_STATE_VALUE==false || ServicesStateBroadcastReceiver.VOICE_SERVICE_STATE_VALUE==false)
{
Toast.makeText(NgfrApp.getContext(),NgfrApp.getContext().getResources().getString(R.string.restarting_services),Toast.LENGTH_SHORT).show();
//restartingServices();
}
else
{
Toast.makeText(NgfrApp.getContext(),NgfrApp.getContext().getResources().getString(R.string.all_already_running),Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
}
MainActivity.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/"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<android.support.design.widget.TabLayout
android:id="#+id/activity_main_tabLyout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/activity_main_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
MainActivity.java, I only included relevant code:
public class MainActivity extends AppCompatActivity {
private static String TAG = "Main";
private static final int CHECK_BT_CODE = 1;
private static final int CHECK_TTS_CODE = 2;
//global boolean flags that will communicate the state of the system at all times
//bluetooth related flags
public boolean isBleSupported = false;
public boolean isBluetoothEnabled = false;
public boolean accessBluetoothManager= false;
public boolean nearbyDevices = false;
//configuration data related
public boolean isConfigurationLoadedCorrectly = false;
//text to speech related
public boolean isTextToSpeechSupported = false;
private Context context = null;
private ServicesStateBroadcastReceiver servicesStateBroadcastReciever = null;
private ViewPager mainViewPager;
private TabLayout tabLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "Activity started!!");
context = this;
setContentView(R.layout.activity_main);
MainActivityViewPager adapter = new MainActivityViewPager(getSupportFragmentManager());
mainViewPager = (ViewPager) findViewById(R.id.activity_main_viewPager);
mainViewPager.setAdapter(adapter);
tabLayout = (TabLayout) findViewById(R.id.activity_main_tabLyout);
tabLayout.setupWithViewPager(mainViewPager );
}
}
The adapter for my fragments, FragmentStatePagerAdapter:
package x.core.views;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import x.BiometricsFragment;
import x.ServicesFragment;
public class MainActivityViewPager extends FragmentStatePagerAdapter {
public MainActivityViewPager(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment returnFragment;
switch(position) {
case 0:
returnFragment = ServicesFragment.newInstance();
break;
case 1:
returnFragment = BiometricsFragment.newInstance();
break;
default:
return null;
}
return returnFragment;
}
#Override
public int getCount() {
return 2;
}
public CharSequence getPageTitle(int position) {
CharSequence title;
switch (position) {
case 0:
title = "Services";
break;
case 1:
title = "Biometrics";
break;
default:
return null;
}
return title;
}
}
Thanks
only for corner clicking use this kind of logic
<FrameLayout
android:layout_width="50dp"
android:layout_height="50dp">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#color/colorAccent" />
<TextView
android:id="#+id/tvtttt"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="right"
android:background="#F00" />
</FrameLayout>
main activity.java
package abhilmohan.blogspot.com;
import android.R.string;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.ActionBar;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
EditText amount1;
EditText amount2;
EditText amount3;
EditText amount4;
Button calculate;
double w=0;
double x=0;
double y=0;
double z=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
public void initcontrols() {
amount1=(EditText)findViewById(R.id.editText1);
amount2=(EditText)findViewById(R.id.editText2);
amount3=(EditText)findViewById(R.id.editText3);
amount4=(EditText)findViewById(R.id.editText4);
calculate=(Button)findViewById(R.id.button1);
}
public void calculate() {
w=Double.parseDouble(amount1.getText().toString());
x=Double.parseDouble(amount2.getText().toString());
y=w/12;
amount3.setText(Double.toString(y));
z=w*x/100;
amount4.setText(Double.toString(z));
}
public void gotoactivity (View v) {
Intent intent = new Intent(this,ResultPage.class);
calculate();
startActivity(intent);
}
am not getting result while calling calculator() void method on button click.i want my results to be published in two textviews created in reulst_page layout
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:gravity="left"
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="abhilmohan.blogspot.com.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/ctc"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:inputType="number"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/TDS"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:inputType="number"
android:ems="10"
android:padding="20dp"
android:paddingBottom="50dp" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button1"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/ok"
android:textColor="#ffffff"
android:onClick="gotoactivity" />
</LinearLayout>
</RelativeLayout>
resultpage.java
package abhilmohan.blogspot.com;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.app.ActionBar;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
public class ResultPage extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_page);
getActionBar().setDisplayHomeAsUpEnabled(true);
ActionBar bar= getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff0000")));
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()== android.R.id.home)
{
finish();
}
return super.onOptionsItemSelected(item);
}
}
result_page.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="40dp"
android:layout_marginRight="40dp"
android:text="#string/amount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="75dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="20dp"
android:layout_marginTop="-15dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:textColor="#000000"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<TextView
android:id="#+id/textView2"
style="#style/text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="90dp"
android:layout_marginLeft="40dp"
android:layout_marginTop="-30dp"
android:text="#string/tdsamount"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="-70dp"
android:background="#drawable/rounded_edit_text"
android:ems="10"
android:inputType="number"
android:padding="20dp"
android:paddingBottom="50dp"
android:clickable="false"
android:cursorVisible="false"
android:focusable="false"
android:focusableInTouchMode="false" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="177dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="60dp"
android:background="#drawable/button_style"
android:text="#string/rate"
android:textColor="#ffffff" />
</LinearLayout>
At the moment you are executing calculate() in the MainActivity.java second activity called ResultPage doesn't exist, therefore you can't change it's view (editText3and editText4).
In order to pass data to another activity you should fill your Intent with some extra data and then in your ResultPage activity's onCreate you would get underlying extras.
EDIT
MainActivity.java
public void gotoactivity (View v) {
calculate();
Intent intent = new Intent(this, ResultPage.class);
intent.putExtra("AMOUNT_3", y);
intent.putExtra("AMOUNT_4", z);
startActivity(intent);
}
ResultPage.java inside onCreate
Bundle extras = getIntent().getExtras();
if (extras != null) {
int amount3 = extras.getInt("AMOUNT_3");
int amount4 = extras.getInt("AMOUNT_4");
}
I have made a CustomTypeDialog class and what I want is to use EditText which is not in the active layout. I get a nullpointer exception when I try to click one of the buttons, which I think is because they are not in the active layout. Can you help me solve this? The dialog is called in an activity from another class.
package dk.droidrun.droidrunapp;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
public class CustomTypeDialog extends Dialog {
ImageButton routeType;
EditText txtType;
Button imageRun, imageBike, imageWalk;
public CustomTypeDialog(final Context context) {
super(context);
this.setContentView(R.layout.customtype_dialog);
routeType = (ImageButton)findViewById(R.id.saveRoute_activityType);
txtType = (EditText)findViewById(R.id.saveRoute_typeTxt);
imageRun = (Button)findViewById(R.id.dialog_btn1);
imageBike = (Button)findViewById(R.id.dialog_btn2);
imageWalk = (Button)findViewById(R.id.dialog_btn3);
setTitle("Select activity type");
show();
imageRun.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtType.setText("Run");
routeType.setBackgroundResource(R.drawable.track_run);
}
});
imageBike.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtType.setText("Bike");
routeType.setBackgroundResource(R.drawable.track_bike);
}
});
imageWalk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
txtType.setText("Walk");
routeType.setBackgroundResource(R.drawable.track_walk);
}
});
}
}
This is my customtype_dialog.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"
tools:context=".AutoMode"
android:background="#color/black" >
<RelativeLayout
android:id="#+id/dialog_relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:layout_above="#+id/dialog_relativeLayout2"
android:layout_centerHorizontal="true" >
<Button
android:id="#+id/dialog_btn1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="#drawable/track_run"
android:layout_alignRight="#+id/dialog_relativeLayout1"
android:layout_alignTop="#+id/dialog_relativeLayout1"
/>
<Button
android:id="#+id/dialog_btn2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:background="#drawable/track_bike"
android:layout_alignTop="#+id/dialog_relativeLayout1"
android:layout_toRightOf="#+id/dialog_btn1"
/>
<Button
android:id="#+id/dialog_btn3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="3dp"
android:layout_toRightOf="#+id/dialog_btn2"
android:background="#drawable/track_walk"
/>
</RelativeLayout>
</RelativeLayout>
saveroutes.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:orientation="vertical"
android:background="#color/black"
tools:context=".SaveRouteActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="#string/saveRoute"
android:textColor="#color/white"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:layout_marginTop="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7a0100"
android:text="Enter a name for the route" />
<EditText
android:id="#+id/saveRoute_nameRoute"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="#string/saveRoute_name"
android:textColor="#color/white"
android:background="#4e4751"
android:inputType="textPersonName" >
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7a0100"
android:text="Describe your route" />
<EditText
android:id="#+id/saveRoute_desciptionTxt"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ems="10"
android:hint="#string/saveRoute_description"
android:textColor="#color/white"
android:background="#4e4751"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#7a0100"
android:text="Activity type (e.g. running)"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal" >
<EditText
android:id="#+id/saveRoute_typeTxt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="17dip"
android:ems="10"
android:layout_marginLeft="30dp"
android:hint="#string/saveRoute_type"
android:textColor="#color/white"
android:background="#4e4751" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/saveRoute_activityType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/track_walk" />
</LinearLayout>
<Button
android:id="#+id/saveRoute_saveBtn"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="#color/white"
android:text="#string/saveRoute_savebutton" />
<Button
android:id="#+id/saveRoute_cancelBtn"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="#color/white"
android:text="#string/saveRoute_cancel" />
</LinearLayout>
You cannot access views from another layout (your activity) using findViewById within the dialog view.
You need to add a callback listener for when the buttons on your dialog are clicked:
public interface OnDialogClickListener {
void onDialogImageRunClick();
}
public class CustomTypeDialog extends Dialog {
private final OnDialogClickListener listener;
public CustomTypeDialog(final Context context, OnDialogClickListener listener) {
this.listener = listener;
}
....
imageRun.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
listener.onDialogImageRunClick();
}
);
}
Then when you create your dialog in your Activity where you have access to the view:
new CustomTypeDialog(context, new CustomTypeDialog.OnDialogClickListener() {
#Override
public void onDialogImageRunClick() {
txtType.setText("Run");
routeType.setBackgroundResource(R.drawable.track_run);
}
});
I am fairly new to android and am writing an app that will solve physics problems. The math is going well thanks to some help from these forums, but when I try to start my activity from a list it comes up with a nullpointerexception in the onCreate Method of the new activity. This doesn't seem to make much sense though, because all thats there is a submit button that executes the math from some EditText views. Here is my code.
package android.physicsengine;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import java.lang.Math;
public class ProjectileMotion extends Activity {
private EditText acceleration;
private EditText finalVelocity;
private EditText initialVelocity;
private EditText time;
private EditText deltay;
private EditText velocity;
private EditText deltax;
private Button submitButton;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
acceleration = (EditText)findViewById(R.id.acceleration);
double a = Doublify(acceleration);
finalVelocity = (EditText)findViewById(R.id.finalVelocity);
double vf = Doublify(finalVelocity);
initialVelocity = (EditText)findViewById(R.id.intitialVelocity);
double vi = Doublify(initialVelocity);
time = (EditText)findViewById(R.id.time);
double t = Doublify(time);
deltay = (EditText)findViewById(R.id.deltay);
double y = Doublify(deltay);
velocity = (EditText)findViewById(R.id.velocity);
double vx = Doublify(velocity);
deltax = (EditText)findViewById(R.id.deltax);
double x = Doublify(deltax);
//Y Axis
if(time.getText()==null && deltay.getText()==null){
time.setText(Double.toString((vf-vi)/a));
deltay.setText(Double.toString(((vf-vi)/a)+(a*Math.pow(((vf-vi)/a),2))));
}
if(acceleration.getText()==null && deltay.getText()==null){
acceleration.setText(Double.toString((vf-vi)/t));
deltay.setText(Double.toString((vi*t+.5*((vf-vi)/t))*Math.pow(t,2)));
}
if(acceleration.getText()==null && time.getText()==null){
acceleration.setText(Double.toString(((Math.pow(vf,2)-Math.pow(vi,2)))/2*y));
time.setText(Double.toString(2*y*(vf-vi)/(Math.pow(vf,2)-vi)));
}
if(initialVelocity.getText()==null && deltay.getText()==null){
initialVelocity.setText(Double.toString(vf-a*t));
deltay.setText(Double.toString((vf-a*t)*t+.5*a*Math.pow(t,2)));
}
if(initialVelocity.getText()==null && time.getText()==null){
initialVelocity.setText(Double.toString(Math.sqrt(Math.pow(vf,2)-2*a*y)));
time.setText(Double.toString((vf-Math.sqrt(Math.pow(vf,2)-2*a*y))/2));
}
if(initialVelocity.getText()==null && acceleration.getText()==null){
initialVelocity.setText(Double.toString(vf-2*(vf-y/t)));
acceleration.setText(Double.toString((2/t)*(vf-y/t)));
}
if(finalVelocity.getText()==null && deltay.getText()==null){
finalVelocity.setText(Double.toString(vi+a*t));
deltay.setText(Double.toString(vi*t+.5*a*Math.pow(t,2)));
}
if(finalVelocity.getText()==null && time.getText()==null){
finalVelocity.setText(Double.toString(Math.sqrt(Math.pow(vi,2)+2*a*y)));
time.setText(Double.toString(((Math.sqrt(Math.pow(vi,2)+2*a*y)-vi))/a));
}
if(finalVelocity.getText()==null && acceleration.getText()==null){
acceleration.setText(Double.toString(2*(y-vi*t)/Math.pow(t,2)));
finalVelocity.setText(Double.toString(vi+(2*(y-vi*t)/t)));
}
if(finalVelocity.getText()==null && initialVelocity.getText()==null){
initialVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t));
finalVelocity.setText(Double.toString((y-.5*a*Math.pow(t,2))/t)+a*t);
}
}
});
}
private double Doublify(EditText editText){
if(editText.getText()!= null){
return Double.parseDouble(editText.getText().toString());
}
return 0;
}
}
and the XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableRow>
<TextView android:text="Projectile Motion Engine"
android:textSize="25dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:layout_gravity="center" />
</TableRow>
<TableRow>
<TextView android:text="X axis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:textStyle="bold"/>
<TextView android:text="Y axis"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<TextView android:text="accel(m/s^2)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/acceleration"
android:text="9.8"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="deltax(m)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/deltax"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="init v(m/s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/intitialVelocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="v ="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/velocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="final v(m/s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/finalVelocity"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView android:text="time(s)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/time"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView android:text="deltay(m)="
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<EditText android:id="#+id/deltay"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button android:id="#+id/submitButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="Launch" />
</TableRow>
</TableLayout>
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton.setOnClickListener(new OnClickListener() {
You forgot to assign your submitButton (with findViewById)
super.onCreate(savedInstanceState);
setContentView(R.layout.projectile_motion_layout);
submitButton = (Button) findViewById((R.id.submitButton); // new line
submitButton.setOnClickListener(new OnClickListener() {
Based on the code you've posted, it appears that you call
submitButton.setOnClickListener(new OnClickListener() {
before instantiating submitButton with a value. This would cause a NullPointer
projectile_motion_layout may not be in your android manifest. I would check that first.
You can find the Application Nodes under the Application tab in the manifest.