Add a layout dynamically, to overlapp the other layout
I'm writing a "Welcome Screen" for my application, that runs when
application launches for the first time. What I want: A transparent layout
to be overlapped on the root layout, dynamically through code. like this
image:
but when I run my app, It crashes due to NULLPOINTEREXCEPTION. even when I
didn't add the second layout
Problem 1: Why first layout doesn't show up, and app crashes?
Problem 2: How to show the second layout?
thanks in advance....
Authentication.java
public class Authentication extends Activity {
private RelativeLayout rootLayout;
public static Context CONTEXT;
public Authentication(){
CONTEXT=this;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
rootLayout=new RelativeLayout(CONTEXT);
LinearLayout firstLayout=(LinearLayout)
findViewById(R.layout.authentication);
rootLayout.addView(firstLayout);
setContentView(rootLayout);
if(Util.isFirstLaunch(CONTEXT)){
//Add the second layout
}
}
}
authentication.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/authentication"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background" >
<TextView
android:id="@+id/textView_login"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="12dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_gravity="center_horizontal"
android:text="@string/loginText"
android:textSize="18sp" />
<EditText
android:id="@+id/editText_username"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_gravity="center_horizontal"
android:nextFocusDown="@+id/editText_password"
android:inputType="textPersonName"
android:hint="@string/username" />
<EditText
android:id="@+id/editText_password"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="12dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_gravity="center_horizontal"
android:inputType="textPassword"
android:hint="@string/password" />
<Button
android:id="@+id/button_submit"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/button"
android:text="@string/submit"
android:textColor="#e1ecff" />
</LinearLayout>
No comments:
Post a Comment