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.
Related
I have an activity and when I click on the "Register" TextView a fragment will open and in that fragment all the Registration detail is there.But when I click on the textview the Fragment is loaded successfully but it did'nt cover up the entire screen.
Here is my code:
MainActivity.java
Register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.support.v4.app.FragmentManager fragmentManager=getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
Fragments fragments=new Fragments();
fragmentTransaction.replace(R.id.Fragment_Register,fragments);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
}
});
}
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.user.attendance.MainActivity"
android:background="#drawable/blurbackgound"
android:padding="10dp"
android:focusableInTouchMode="true"
>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="WELCOME"
android:textColor="#color/white"
android:textStyle="bold"
android:fontFamily="monospace"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:id="#+id/login_mobile_number"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:background="#drawable/edit_text_border"
android:padding="15dp"
android:textColor="#color/white"
android:inputType="number"
android:hint="Enter mobile number"
android:gravity="center"
android:maxLength="10"
android:textColorHint="#color/hint_color"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_local_phone_black_24dp"
android:layout_below="#id/title"
android:layout_marginLeft="30dp"
android:layout_marginTop="73dp"
android:id="#+id/phonelogo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mb_counter"
android:layout_below="#id/title"
android:layout_marginLeft="300dp"
android:layout_alignBaseline="#id/login_mobile_number"
android:text="abssh"
android:textColor="#color/white"
/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/login_mobile_number"
android:layout_marginTop="25dp"
android:background="#drawable/edit_text_border"
android:paddingRight="50dp"
android:hint="Password"
android:gravity="center"
android:textColorHint="#color/hint_color"
android:inputType="textPassword"
android:textColor="#color/white"
android:id="#+id/login_password"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="1dp"
android:layout_below="#id/login_password"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/white"
android:text="Student"
android:textColor="#color/white"
android:id="#+id/Radio_button_student"
android:layout_marginLeft="19dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:buttonTint="#color/white"
android:text="Teacher"
android:textColor="#color/white"
android:id="#+id/Radio_button_teacher"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SHOW"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_alignRight="#id/login_password"
android:layout_alignBaseline="#id/login_password"
android:id="#+id/password_visibility"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_lock_outline_black_50dp"
android:layout_marginLeft="30dp"
android:layout_below="#id/phonelogo"
android:layout_marginTop="39dp"
/>
<Button
android:stateListAnimator="#null"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Login"
android:id="#+id/login"
android:background="#drawable/login_buttom"
android:textColorHint="#color/hint_color"
android:layout_below="#id/login_password"
android:layout_marginTop="50dp"
android:layout_marginLeft="35dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FORGOT PASSWORD"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginTop="18dp"
android:layout_marginLeft="48dp"
android:id="#+id/forgot_password"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="#color/white"
android:layout_alignBaseline="#id/forgot_password"
android:layout_marginLeft="170dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTER"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginLeft="185dp"
android:layout_marginTop="20dp"
android:id="#+id/Register"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/Fragment_Register"></RelativeLayout>
</RelativeLayout>
Fragments.java
package com.example.user.attendance;
import android.app.FragmentManager;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import de.hdodenhof.circleimageview.CircleImageView;
public class Fragments extends Fragment {
Button Register_Cancel_fullname, Register_Cancel_email, Register_Cancel_phone,
Register_Cancel_password, Sign_up,Register_Cancel_Confirm_Password;
String Passcode,Confirm_Passcode;
EditText Full_Name, Email_Address, Phone_number, Password_register,Confirm_Password_register;
CircleImageView Register_add_photo;
LinearLayout select_photo_from_camera,select_photo_from_gallery;
TextView textView,hint_textview_circular_image_view;
// RadioButton Category_teacher,Category_student;
RadioGroup Teacher_student;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View myfragmentVieew = inflater.inflate(R.layout.fragment_signup, container, false);
//Edit Text
Full_Name = (EditText) myfragmentVieew.findViewById(R.id.Register_name_and_surname);
Email_Address = (EditText) myfragmentVieew.findViewById(R.id.Register_Email_address);
Phone_number = (EditText) myfragmentVieew.findViewById(R.id.Register_Phone);
Password_register = (EditText) myfragmentVieew.findViewById(R.id.Register_Password);
Confirm_Password_register=(EditText)myfragmentVieew.findViewById(R.id
.Confirm_Password_Register);
//Button
Sign_up = (Button) myfragmentVieew.findViewById(R.id.Register_Signup);
Register_Cancel_fullname = (Button) myfragmentVieew.findViewById(R.id.Register_First_Cancel_Button);
Register_Cancel_email = (Button) myfragmentVieew.findViewById(R.id.Register_Second_Cancel_Button);
Register_Cancel_phone = (Button) myfragmentVieew.findViewById(R.id.Register_Third_Cancel_Button);
Register_Cancel_password = (Button) myfragmentVieew.findViewById(R.id.Register_fourth_Cancel_Button);
Register_Cancel_Confirm_Password=(Button)myfragmentVieew.findViewById(R.id
.Register_Cancel_Confirm_Password_Button);
Register_add_photo=(CircleImageView)myfragmentVieew.findViewById(R.id.Register_add_photo);
//TextView
textView = (TextView) myfragmentVieew.findViewById(R.id.Register_textview);
hint_textview_circular_image_view=(TextView)myfragmentVieew.findViewById(R.id
.hint_of_image_view);
return myfragmentVieew;
}
}
Here is what I am getting:
Remove this line from root layout.
android:padding="10dp"
This will solve the problem.
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.
I have used cutsom dialog box in my MainActivity for popup screen.I have added cross button to close
the popup screen. here in my code, that cross button is showing inside
the popup screen.
Now what i want is it has to show at the border of the popup screen.
please help me to get this..
Below is my code..any help would be appreciated...thanks in advance..
Java File
HomePage.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v4.app.DialogFragment;
public class HomePage extends Activity {
final Context context = this;
Button b1;
Button b2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
b1 = (Button) findViewById(R.id.button6);
b2 = (Button) findViewById(R.id.button7);
b2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HomePage.this,RegisterPage.class);
startActivity(intent);
}
});
b1.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi")
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_login_page);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay(); // getting the screen size of device
Point size = new Point();
display.getSize(size);
int width = size.x - 20; // Set your heights
int height = size.y - 80; // set your widths
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
dialog.show();
ImageView image = (ImageView) dialog.findViewById(R.id.cancel_btn);
image.setImageResource(R.drawable.cancel2);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//dialog.dismiss();
Intent intent = new Intent(HomePage.this,CategoryPage.class);
startActivity(intent);
}
});
dialog.show();
}
});
}
}
XML File
activity_home_page.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:background="#fff"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:src="#drawable/miiskylogo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="163dp"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<Button
android:id="#+id/button6"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:drawableLeft="#drawable/lock"
android:text="Login with SVAPP" />
<Button
android:id="#+id/button7"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/regis"
android:text="Register with SVAPP" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
activity_login_page.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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/cancel2" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/miiskylogo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginRight="15dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/loginbutton"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:padding="10dp"
android:layout_marginRight="20dp"
android:text="Lorem Ipsum dolor sit amet,"
android:background="#drawable/loginedit"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
I want cross button something like the image below.
Click Here
Try this solution:
<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="#fff"
tools:context="com.example.miiskyproject.Login" >
<LinearLayout
android:id="#+id/cancel_layuot"
android:layout_width="match_parent"
android:gravity="right"
android:background="#android:color/transparent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_below="#+id/cancel_layuot"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/left_arrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot" >
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="280dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:text="Lorem Ipsum dolor sit amet,"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
You will see something like this:
Just replace image ic_launcher with the appropriated image.
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.
i am learning this Java language and trying to make my own app, but i get this error whenever i type in this method. Howcome does it give me that error?
I am following the Tutorial from Travis on youtube and he doesn't get this errror, i can't figure this out..
package com.nichlas.denfoerste;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class TutorialOne extends Activity implements OnCheckedChangeListener{
TextView textOut;
EditText textIn;
RadioGroup gravityG, styleG;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorial1);
textOut = (TextView) findIdByView(R.id.tvChange);
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
}
}
My XML file
<?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" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:gravity="center"
android:text="Style"
android:textSize="25sp" />
<TextView
android:id="#+id/tvGravity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:gravity="center"
android:text="Gravity"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioGroup
android:id="#+id/rgStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50" >
<RadioButton
android:id="#+id/rbNormal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Normal" />
<RadioButton
android:id="#+id/rbItalic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Italic" />
<RadioButton
android:id="#+id/rbBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bold" />
</RadioGroup>
<RadioGroup
android:id="#+id/rgGravity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.50" >
<RadioButton
android:id="#+id/rbLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Left" />
<RadioButton
android:id="#+id/rbCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Center" />
<RadioButton
android:id="#+id/rbRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Right" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/tvChange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Generate here" />
<Button
android:id="#+id/bGenerate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Generate"
android:textSize="25sp" />
</LinearLayout>
Try replacing the following line.
textOut = (TextView) findIdByView(R.id.tvChange);
with
textOut = (TextView) findViewById(R.id.tvChange);
textOut = (TextView) findIdByView(R.id.tvChange);
replace this with bellow line...
textOut = (TextView) findViewById(R.id.tvChange);
And you are done.