First activity won't run on AVD - android

I created an application, my first, and am having problems running it on an AVD. Won't load the first activity, just says 'Unfortunately, FussyFestivalrV7 has stopped. This is the main starting activity:
package com.example.fussyfestivalr;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button switchButton = (Button) findViewById(R.id.button1);
switchButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, News.class);
startActivity(intent);
}
});
}
}
And my layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#string/title"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/newsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="#string/news" />
<Button
android:id="#+id/exit"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="17dp"
android:layout_toRightOf="#+id/title"
android:text="#string/exit" />
<Button
android:id="#+id/bands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/exit"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp"
android:text="#string/bands" />
<Button
android:id="#+id/fafq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bands"
android:layout_centerHorizontal="true"
android:layout_marginBottom="53dp"
android:text="#string/fafq" />
<Button
android:id="#+id/profiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/fafq"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="#string/festivals" />

Check whether you have </RelativeLayout>.
I hope to help.
Paul.

Related

Implementing formulas into each value in the spinner which will change the result everytime the user change selected value

I am creating a diet app for myself and I do not know how to transfer result from one calculation which was done in a different activity and use it in another one.
To make things more complicated, I want my spinner in MoreLooseWeightDetails.class to have a list of different diet types which have different fat, proteins and carb ratio. Every time the user choose different type it should automatically change the ratio.
This is where the calculation is being done and has to be trnasfered to MoreLooseWeightDetails.class
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class LooseWeight extends AppCompatActivity {
TextView TotalCal;
EditText numb2;
Spinner ActLvl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loose_weight);
numb2 = (EditText) findViewById(R.id.value1);
ActLvl = (Spinner) findViewById(R.id.value2);
TotalCal = (TextView)findViewById(R.id.resultDisplay);
final Spinner ActLvl = (Spinner)findViewById(R.id.value2);
ArrayAdapter<String> myAdapter = new ArrayAdapter<>(LooseWeight.this, android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.lvl));
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ActLvl.setAdapter(myAdapter);
Button calcBtn = (Button)findViewById(R.id.result);
calcBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick (View view) {
float numb3 = Float.parseFloat(numb2.getText().toString());
float a = numb3 * 24;
float b = a * Float.parseFloat(ActLvl.getSelectedItem().toString());
float c = b - 500;
TotalCal.setText(Float.toString(c));
}
});
Button extra = (Button)findViewById(R.id.advance);
extra.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(),MoreLooseWeightDetails.class);
startActivity(intent);
}
});
}
}
Here is the MoreLooseWeightDetails.class
package com.fitup.fit_up;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MoreLooseWeightDetails extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_more_loose_weight_details);
}
}
Here is the MoreLooseWeightDetails.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:id="#+id/activity_more_loose_weight_details"
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.fitup.fit_up.MoreLooseWeightDetails">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/Title3"
tools:text="More"
android:textSize="36sp" />
<TextView
android:text="Select Type of Diet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Title3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/Info3"
android:textSize="30sp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Info3"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="#+id/spinner" />
<TextView
android:text="You Should Eat :"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:id="#+id/Info4"
android:textSize="30sp"
android:layout_below="#+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="Protein (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit1"
android:textSize="24sp"
android:layout_below="#+id/Info4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="78dp" />
<TextView
android:text="Fat (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit3"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/result1"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignLeft="#+id/result2"
android:layout_alignStart="#+id/result2" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/unit2"
android:id="#+id/result2"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/result3"
android:layout_alignStart="#+id/result3" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit2"
android:id="#+id/result3"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/unit2"
android:layout_toEndOf="#+id/unit2" />
<TextView
android:text="Carbohydrates (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:id="#+id/unit2"
android:textSize="24sp"
android:layout_below="#+id/unit1"
android:layout_alignRight="#+id/unit1"
android:layout_alignEnd="#+id/unit1" />
</RelativeLayout>

Button redirects doesn't work in Android Studio

When I create this project I give the company domain as eu.kudan.kudansamples.
When I run this code, I get an error message Unfortunatly, ArMcqEvaluator has stopped
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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="kudan.eu.armcqevaluator.MainActivity">
<TextView
android:layout_width="77dp"
android:layout_height="36dp"
android:text="Email : "
android:id="#+id/emailtxt"
android:layout_x="29dp"
android:layout_y="78dp" />
<TextView
android:layout_width="79dp"
android:layout_height="31dp"
android:text="Password : "
android:id="#+id/passwordtxt"
android:layout_x="29dp"
android:layout_y="114dp" />
<EditText
android:layout_width="216dp"
android:layout_height="wrap_content"
android:id="#+id/email"
android:layout_x="105dp"
android:layout_y="60dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:layout_x="105dp"
android:layout_y="93dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log in"
android:id="#+id/login"
android:layout_x="180dp"
android:layout_y="156dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resistor"
android:id="#+id/registor"
android:layout_x="82dp"
android:layout_y="156dp"
android:onClick="#string/abc_action_bar_home_description" />
</AbsoluteLayout>
MainActivity.java
package kudan.eu.armcqevaluator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import eu.kudan.kudan.ARAPIKey;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener{
Button login,registor;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ARAPIKey key = ARAPIKey.getInstance();
key.setAPIKey("GAWAE-FBVCC-XA8ST-GQVZV-93PQB-X7SBD-P6V4W-6RS9C-CQRLH-78YEU-385XP-T6MCG-2CNWB-YK8SR-8UUQ");
login = (Button)findViewById(R.id.login);
registor = (Button)findViewById(R.id.registor);
}
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,Registration.class));
}
}
regigtration.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email :"
android:id="#+id/emaillbl"
android:layout_x="42dp"
android:layout_y="35dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:id="#+id/email"
android:layout_x="170dp"
android:layout_y="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name :"
android:id="#+id/namelbl"
android:layout_x="42dp"
android:layout_y="70dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:id="#+id/name"
android:layout_x="170dp"
android:layout_y="55dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Institute :"
android:id="#+id/institutelbl"
android:layout_x="42dp"
android:layout_y="105dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:id="#+id/institute"
android:layout_x="170dp"
android:layout_y="91dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Position :"
android:id="#+id/positionlbl"
android:layout_x="42dp"
android:layout_y="150dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:id="#+id/position"
android:layout_x="170dp"
android:layout_y="127dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password :"
android:id="#+id/passwordlbl"
android:layout_x="42dp"
android:layout_y="186dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/password"
android:layout_x="170dp"
android:layout_y="163dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Conform password :"
android:id="#+id/textView7"
android:layout_x="39dp"
android:layout_y="224dp" />
<EditText
android:layout_width="172dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/conformpassword"
android:layout_x="170dp"
android:layout_y="196dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="#+id/submit"
android:layout_x="130dp"
android:layout_y="253dp" />
</AbsoluteLayout>
Registration.java
package kudan.eu.armcqevaluator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class Registration extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
}
}
You can't call override methods from XML onClick. Implement a public method and do your functionality on that method.
on XML file:
android:onClick="RedirectRegisterMethod"/>
on java file:
public void RedirectRegisterMethod(View v) {
// do your functionality here
}
you need to add onClickListener method to your button.
registor.setOnClickListener(this);
Then only the onclickListener will work for that button.
Also check for activity entry in manifest file for registration activity.

Android setonclicklistener crashed

I am trying to go back to previous activity after a linear layout or back button is touched however I am getting the nullpointer exception error even tough I have initialized the button and layout in onCreate method
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.LinearLayout.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
My Java file
package com.profile;
import android.app.Activity;
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.ImageButton;
import android.widget.LinearLayout;
import com.R;
public class AboutActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_button_linear_layout);
ImageButton backButton=(ImageButton) findViewById(R.id.back_profile_btn);
backlayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
}
}
My XML file
<?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:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.profile.AboutActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#color/colorPrimaryDark">
<LinearLayout
android:id="#+id/back_profile_layout"
android:layout_width="55dp"
android:layout_height="match_parent"
android:gravity="start|center_vertical"
android:orientation="vertical">
<ImageButton
android:id="#+id/back_profile_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:adjustViewBounds="true"
android:background="#color/transparentBackgroundPrimaryDark"
android:maxHeight="20dp"
android:maxWidth="20dp"
android:scaleType="centerInside"
android:src="#drawable/back_100px" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="About"
android:textAllCaps="true"
android:textColor="#color/colorPrimary"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Terms"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:drawable="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Terms and Conditions"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Data_policy"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:color="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Data policy"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<Button
android:id="#+id/Licences"
android:layout_width="345dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_button_primary"
android:drawable="#color/colorPrimary"
android:clickable="true"
android:textAllCaps="false"
android:layout_gravity="center"
android:text="Licences"
android:textColor="#color/colorPrimaryDark"
android:textSize="18sp"
/>
<android.support.v4.widget.Space
android:layout_width="10sp"
android:layout_height="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="209dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Version 1.1.1000"
android:gravity="center"
android:textColor="#color/colorAccent"
android:textSize="16sp"
android:textStyle="bold"
android:layout_weight="0.87" />
</LinearLayout>
Change this line
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_button_linear_layout);
to this
LinearLayout backlayout=(LinearLayout) findViewById(R.id.back_profile_layout);
because you are assign wrong id to LinearLayout that's why it give you NullPointerExecption.
and also Remove this import com.R; is not require.

Query on a Text view

I want to display the following output:
Name : Sangeetha
Usn : 4AL09IS025
Address : Anderi West, Mubai.
Name and usn are displaying properly. But my Address is not displaying. What's the problem. Here's my code. Can anyone tell me what's the problem?MainActivity.java is the my main activity class.
package com.example.assignment3;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends ActionBarActivity implements OnClickListener {
Button btn;
EditText etext1;
EditText etext2;
EditText etext3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etext1 = (EditText) findViewById(R.id.edit_name);
etext2 = (EditText) findViewById(R.id.edit_usn);
etext3 = (EditText) findViewById(R.id.edit_add);
btn = (Button) findViewById(R.id.submit);
/** Called when the user clicks the Submit button */
btn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
Intent intent = new Intent(this, Details.class);
intent.putExtra("name", etext1.getText().toString());
intent.putExtra("usn", etext2.getText().toString());
intent.putExtra("address", etext3.getText().toString());
startActivity(intent);
}
}
Display.java is my Display activity to receive the intent sent by Main Activity.java
package com.example.assignment3;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;
public class Details extends ActionBarActivity {
TextView text1;
TextView text2;
TextView text3;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
text1=(TextView)findViewById(R.id.new_name);
text2=(TextView)findViewById(R.id.new_usn);
text3=(TextView)findViewById(R.id.new_add);
Intent intent=getIntent();
String Name=intent.getStringExtra("name");
String Usn=intent.getStringExtra("usn");
String Address=intent.getStringExtra("add");
text1.setText(Name);
text2.setText(Usn);
text3.setText(Address);
}
}
Two layout files. First one is for the first activity(input) and 2nd one is for 2nd activity(output).main_activity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.assignment3.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/name"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingLeft="20.3dp"
android:text="#string/name" />
<EditText
android:id="#+id/edit_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:gravity="center"
android:inputType="textMultiLine"
android:hint="#string/edit_name" />
<TextView
android:id="#+id/usn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_marginTop="30dp"
android:paddingLeft="32dp"
android:text="#string/usn" />
<EditText
android:id="#+id/edit_usn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/edit_name"
android:layout_marginLeft="85dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:inputType="textMultiLine"
android:hint="#string/edit_usn" />
<TextView
android:id="#+id/add"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#+id/usn"
android:layout_marginTop="40dp"
android:text="#string/add" />
<EditText
android:id="#+id/edit_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/edit_usn"
android:layout_marginLeft="85dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:inputType="textMultiLine"
android:hint="#string/edit_add" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_centerHorizontal="true"
android:text="#string/submit"/>
</RelativeLayout>
activity_details.java's layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.assignment3.MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="#+id/name"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:paddingLeft="20.3dp"
android:text="#string/name"
android:textStyle="bold" />
<TextView
android:id="#+id/new_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="10dp" />
<TextView
android:id="#+id/usn"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_marginTop="20dp"
android:paddingLeft="32dp"
android:text="#string/usn"
android:textStyle="bold" />
<TextView
android:id="#+id/new_usn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/new_name"
android:layout_marginLeft="85dp"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/add"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_below="#+id/usn"
android:layout_marginTop="30dp"
android:text="#string/add"
android:textStyle="bold" />
<TextView
android:id="#+id/new_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/new_usn"
android:layout_marginLeft="85dp"
android:layout_marginTop="30dp"
android:singleLine="false" />
</RelativeLayout>
try that ;
Define same string for address
Intent intent=getIntent();
String Name=intent.getStringExtra("name");
String Usn=intent.getStringExtra("usn");
String Address=intent.getStringExtra("address");
text1.setText(Name);
text2.setText(Usn);
text3.setText(Address);
See lines intent.putExtra("address", etext3.getText().toString()); and String Address=intent.getStringExtra("add"); You need to change the add to address to make it work

Activity With buttons show blank

Notice I edited the XML File!!!!
I got an Activity that create a button and when you click on the button it calls to another Activity but when i run the app it's shows just a blank page.
Activity:
package com.elichai.tfillin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
public void OnCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
private void displayCamera() {
Intent i = new Intent(this, CameraActivity.class);
startActivityForResult(i, 0);
}
public void addListenerOnButton() {
final Button button1 = (Button) findViewById(R.id.button1);
//Button button2 = (Button) findViewById(R.id.button2);
//Button button3 = (Button) findViewById(R.id.button3);
//Button button4 = (Button) findViewById(R.id.button4);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
displayCamera();
//finish();
}
});
}
}
And here is the activity_main.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:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:text="#string/button" />
<Button
android:id="#+id/button2"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:text="#string/button" />
<Button
android:id="#+id/button3"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="7dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<Button
android:id="#+id/button4"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_marginLeft="182dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<TextView
android:id="#+id/textView1"
android:layout_width="223dp"
android:layout_height="52dp"
android:layout_marginLeft="85dp"
android:layout_marginTop="215dp"
android:text="#string/switch_cam"
android:textSize="30sp" />
</LinearLayout>
Thanks!
There is nothing wrong with the layout. In your MainActivity class, the onCreate() method signature is written incorrectly. Use onCreate() instead of OnCreate(). (small 'o')
The system calls onCreate() when creating your activity.
Replace the FrameLayout with a vertical LinearLayout
Try using A RelativeLayout in place of FrameLayout unless there was relay a need of using it.
or if you want to use FrameLayout try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="7dp"
android:text="#string/button" />
<Button
android:id="#+id/button2"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="182dp"
android:text="#string/button" />
<Button
android:id="#+id/button3"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="7dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<Button
android:id="#+id/button4"
android:layout_width="166dp"
android:layout_height="216dp"
android:layout_gravity="top"
android:layout_marginLeft="182dp"
android:layout_marginTop="260dp"
android:text="#string/button" />
<TextView
android:id="#+id/textView1"
android:layout_width="223dp"
android:layout_height="52dp"
android:layout_gravity="top"
android:layout_marginLeft="85dp"
android:layout_marginTop="215dp"
android:text="switchcam"
android:textSize="30sp" />
</FrameLayout>
layout_ margins does not work in FrameLayout until you also set your subviews layout gravity e.g.
android:layout_gravity="top"
( for framelayout)

Categories

Resources