EditText null after calling findViewById() - java

I've had this issue for the past couple days, and I can't seem to figure out what's wrong. I feel like I've written these exact lines of code a million times. I have two EditText components that I'm trying to get the text from when a button is clicked. But for some reason I'm getting a NullPointer exception for both the EditTexts. Calling findViewById() finds the buttons just fine, but doesn't seem to resolve the EditTexts.
When I run the application, the UI appears and I am able to click the "Connect" button. Logcat tells me the NullPointerException is coming from line 46 in "MainActivity.java", which is where the first EditText is. I've run tests and have verified that they are null. I can't seem to figure out why though, any insight on resolving the matter would be greatly appreciated. I'm running Android Studio v1.0.2.
MainActivity.java
public class MainActivity extends Activity{
private TextView _ipLabel;
private EditText _ipInput;
private EditText _portInput;
private Button _hostButton;
private Button _connectButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
_ipLabel = (TextView) findViewById(R.id.ip_label);
_ipInput = (EditText) findViewById(R.id.ip_input);
_portInput = (EditText) findViewById(R.id.port_input);
_hostButton = (Button) findViewById(R.id.hostButton);
_connectButton = (Button) findViewById(R.id.connectButton);
_hostButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d("Host Button", "Clicked");
}
});
_connectButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String connectionAddr = _ipInput.getText().toString() + ":";
connectionAddr+= _portInput.getText().toString();
Log.d("Host", connectionAddr);
}
});
}
activity_main.xml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/ip_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-.-.-.-"/>
<Button
android:id="#+id/hostButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Host "/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IP: "/>
<EditText
android:label="#+id/ip_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PORT: "/>
<EditText
android:label="#+id/port_input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/connectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connect"/></LinearLayout>

<EditText
android:label="#+id/port_input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Here it isn't android:label, it should be android:id.
Change this to,
android:id="#+id/port_input"
Also to the other edit text used.

Instead of:
<EditText
android:label="#+id/ip_input" // <-- this should be an id not a label
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
use:
<EditText
android:id="#+id/ip_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

try this..
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="#+id/ip_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="-.-.-.-"/>
<Button
android:id="#+id/hostButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Host "/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IP: "/>
<EditText
android:id="#+id/ip_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PORT: "/>
<EditText
android:id="#+id/port_input"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/connectButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connect"/></LinearLayout>

Related

How to add onclickListener on this Framelayout?

Here is my MainActivity:
public class MainActivity extends AppCompatActivity {
private LinearLayout mStatusBarAllContents;
private FrameLayout mStatusBar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStatusBar = findViewById(R.id.status_bar);
mStatusBarAllContents = findViewById(R.id.status_bar_all_contents);
mStatusBar.setOnClickListener(v -> {
Log.d("TAG", "status");
});
mStatusBarAllContents.setOnClickListener(v -> {
Log.d("TAG", "statusall");
});
}
My Layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/status_bar"
android:layout_width="match_parent"
android:layout_height="60px"
android:background="#drawable/sysheader_bg"
android:descendantFocusability="afterDescendants"
android:orientation="vertical">
<ImageView
android:id="#+id/notification_lights_out"
android:layout_width="22dip"
android:layout_height="match_parent"
android:paddingStart="6dp"
android:paddingBottom="2dip"
android:scaleType="center"
android:visibility="gone"
tools:ignore="RtlCompat" />
<LinearLayout
android:id="#+id/status_bar_all_contents"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<FrameLayout
android:layout_width="174px"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/clock_relativelayout"
android:layout_width="174px"
android:layout_height="match_parent"
android:clickable="true"
android:visibility="visible">
<TextView
android:id="#+id/clock_hour"
android:layout_width="60px"
android:layout_height="54px"
android:gravity="center"
android:includeFontPadding="false"
android:text="05"
android:textColor="#color/white"
android:textSize="52px"
android:textStyle="bold" />
<ImageView
android:id="#+id/clock_coron"
android:layout_width="12px"
android:layout_height="48px"
android:layout_marginTop="9px"
android:layout_toRightOf="#+id/clock_hour"
android:scaleType="fitCenter"
android:src="#drawable/num_12x48_colon" />
<TextView
android:layout_width="60px"
android:layout_height="54px"
android:layout_toRightOf="#+id/clock_coron"
android:gravity="center"
android:includeFontPadding="false"
android:text="30"
android:textColor="#color/white"
android:textSize="52px"
android:textStyle="bold">
</TextView>
</RelativeLayout>
</FrameLayout>
<LinearLayout
android:id="#+id/status_bar_info_layout"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:visibility="visible">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/audio_area"
android:layout_width="786px"
android:layout_height="match_parent"
android:background="#drawable/da_header_sections_background_click_over_info"
android:clickable="true"
android:orientation="horizontal"
android:splitMotionEvents="false">
<FrameLayout
android:id="#+id/audio_info_area"
android:layout_width="708px"
android:layout_height="match_parent"
android:clickable="false">
<TextView
android:id="#+id/audio_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="18px"
android:layout_marginLeft="18px"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="ALOLO"
android:textSize="20sp"
android:visibility="visible" />
<LinearLayout
android:id="#+id/audio_off"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="24px"
android:paddingLeft="24px"
android:paddingEnd="56px"
android:paddingRight="56px"
android:visibility="gone">
<TextView
android:id="#+id/audio_off_text"
android:layout_width="648px"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="6px"
android:layout_marginLeft="6px"
android:ellipsize="end"
android:gravity="left"
android:singleLine="true"
android:text="PowerOFF"
android:textColor="#color/white"
android:textSize="30px">
</TextView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</LinearLayout>
I set onclick on FrameLayout and LinearLayout, i wanna show log is status but when i touch it, nothing happen.
And then, i set android:layout_width="1dp", android:layout_height="1dp" of id: status_bar_all_contents, it show log: status, but status_bar_all_contents will gone, so i dont want that.
So how to fix when i touch it and show log status?
Ps: Sorry for my english is not good.
Layouts typically pass-through clicks to their children.
You can try this solution here disabling all children onclicks and enabling the FrameLaoyuts onclicks. But I don't think that will work with the LinearLayout on top of that.
Android frame layout click listener not working
My advice wrap the entire view in a ConstraintLayout, and position 2 basic <View>s
One <View> that is constrained to match the FrameLayout
One <View> that is constrained to match the LinearLayout
These <View>s will act as overlays.
<View
android:id="#+id/status_bar_overlay"
app:layout_constraintEnd_toEndOf="#id/status_bar"
app:layout_constraintStart_toStartOf="#id/status_bar"
app:layout_constraintTop_toTopOf="#id/status_bar"
app:layout_constraintBottom_toBottomOf="#id/status_bar" />
<View
android:id="#+id/status_bar_all_contents_overlay"
app:layout_constraintEnd_toEndOf="#id/status_bar_all_contents"
app:layout_constraintStart_toStartOf="#id/status_bar_all_contents"
app:layout_constraintTop_toTopOf="#id/status_bar_all_contents"
app:layout_constraintBottom_toBottomOf="#id/status_bar_all_contents" />
Set the two View's onClickListener in the Activity and there you go.

setOnItemClickListener() not working on ExpandableHeightGridView in Fragment

Hello good morning in my view i cant handled the setOnItemClickListener
I am trying to create an application which dynamically lists installed applications in a gridview.I am able to display the applications in a gridview form but not able to make these items clickable. Nothing happens when i click these items. The code inside the setOnItemClickListener does not get triggered on click event.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".Tab2profile">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
//my scrollview
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/MainRLyout"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/girislayout"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/usernameTv"
android:layout_alignParentStart="true"
android:layout_width="wrap_content"
android:layout_margin="10dp"
android:layout_centerVertical="true"
android:textSize="#dimen/text_size_Orta"
android:textColor="#color/cardview_dark_background"
android:layout_height="wrap_content"
tools:ignore="PrivateResource" />
<Button
android:id="#+id/Login_LogOut_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:background="#drawable/logout_rounded"
android:drawableRight="#drawable/logout_icon"
android:padding="0dp"
android:text="#string/Logout_Text_str"
android:textColor="#android:color/white"
android:textSize="12sp"
tools:ignore="RelativeOverlap,RtlHardcoded" />
</RelativeLayout>
//in here i cant handled the item click funktşon
<syr13.comapp4.Custum_Adapters.ExpandableHeightGridView
android:id="#+id/Your_Apps_Li"
android:numColumns="3"
android:layout_below="#id/Your_Apps_Tv"
android:horizontalSpacing="6dp"
android:layout_margin="5dp"
android:verticalSpacing="6dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">
</syr13.comapp4.Custum_Adapters.ExpandableHeightGridView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
I think you can Change your Code
from
button.setOnItemClickListener(this);
To
button.setOnClickListener(this);
for example :-
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.button:
//Do Something
break;
}
}
}

Stop android scrollview prevent parent LinearLayout onclick

I need to allow user to CLICK anywhere on the screen, so I've implemented onClick listener for mainLayout and it worked great.
But the problem is I've got to add a scrollview inside mainLayout to support small screen sizes and after adding scrollview, it blocks the parentLayout (in my case mainLayout) CLICK EVENT.
Just to exaplin this, a sample layout is as follows.
<!-- MAIN LAYOUT WHERE I NEED
THE CLICK EVENT-->
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe"
android:orientation="vertical"
android:onClick="onClick_MainLayout">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"
android:onClick="onClick_Button1"/>
<Button
android:id="#+id/button2"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"
android:onClick="onClick_Button2"/>
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
I searched for this and found various ideas like disableing onClick manually in all other views inside scrollview etc but non of them works.
NOTE: I tried both implementing onClick listener manually in java and adding android:onClick="onClick_MainLayout" in to layout. Both the same.
EDITS ----------------------
All the changes I've done as you (#IntelliJ Amiya) mentioned is as below. Please let me know anything is missing.
<RelativeLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"/>
<Button
android:id="#+id/button2"
android:layout_below="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"/>
<TextView
android:id="#+id/textview1"
android:layout_below="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And in on create
findViewById(R.id.mainLayout).setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
Log.v("MyLogs", "Click Event Fires...");
}
});
Your Scroll view overlaps the linear layout i.e #mainLayout,so
set its height to wrap content
then you can perform onclick for both scroll view buttons and mainlayout.
Pls tell me if i wrong.
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#bebebe"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:id="#+id/mainScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="#+id/button1"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 1"
android:onClick="onClick_Button1"/>
<Button
android:id="#+id/button2"
android:layout_width="100dp"
android:layout_height="40dp"
android:text="TEST BUTTON 2"
android:onClick="onClick_Button2"/>
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Text View"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
JAVA
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick_Button1(View v)
{
Toast.makeText(this, "1ST Button Click", Toast.LENGTH_SHORT).show();
}
public void onClick_Button2(View v)
{
Toast.makeText(this, "2ND Button Click", Toast.LENGTH_SHORT).show();
}
}

Unable to use components of different layout in android main activity

In my activity I am displaying splash(splash.xml) screen for 5 sec and then I am changing content view to my actual layout of main activity(activity_main). But when I am trying to use the components in the my main activity layout(activity_main) I am getting null pointer exception.
Main Activity is
public class MainActivity extends ActionBarActivity {
ProgressBar progressBar2;
EditText userName,password;
static String url;
JSONObject reader;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
new CountDownTimer(5000,1000){
#Override
public void onTick(long millisUntilFinished){}
#Override
public void onFinish(){
//set the new Content of your activity
MainActivity.this.setContentView(R.layout.activity_main);
}
}.start();
progressBar2=(ProgressBar)findViewById(R.id.progressBar2);
progressBar2.setVisibility(View.GONE);
userName=(EditText)findViewById(R.id.userName);
password=(EditText)findViewById(R.id.password);
}
}
when I use any of this components I am getting null pointer exception.
My splash Screen layout file splash.xml
<RelativeLayout
android:layout_height="match_parent"
android:background="#drawable/ic_launcher_web">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="111dp"
/>
</RelativeLayout>
and the main layout(activity_main.xml is)
<LinearLayout
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:weightSum="1">
<EditText
android:layout_width="match_parent"
android:hint="Username"
android:layout_height="wrap_content"
android:id="#+id/userName"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/password"
android:hint="Password"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remember me"
android:id="#+id/checkBox"
android:checked="false"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="#+id/button"
android:onClick="login"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signup"
android:id="#+id/button3"
android:onClick="signUp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/progressBar2"/>
</LinearLayout>
</LinearLayout>
Because your
#Override
public void onFinish(){
//set the new Content of your activity
MainActivity.this.setContentView(R.layout.activity_main);
}
will be executed after 5 seconds.
Set your layout
setContentView(R.layout.activity_main);
before progressBar2=(ProgressBar)findViewById(R.id.progressBar2);

Bringing EditText to front of WebView Android

I have the following code:
public class MainActivity extends ActionBarActivity {
EditText userfield;
EditText passfield;
Button logbtn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userfield = (EditText)findViewById(R.id.editText);
passfield = (EditText)findViewById(R.id.editText2);
logbtn = (Button)findViewById(R.id.button);
GifWebView view = new GifWebView(this, "file:///android_asset/watg.gif");
view.getSettings().setLoadWithOverviewMode(true);
view.getSettings().setUseWideViewPort(true);
setContentView(view);
userfield.bringToFront();
userfield.invalidate();
passfield.bringToFront();
passfield.invalidate();
logbtn.bringToFront();
logbtn.invalidate();
}
As you can see the GifWebView (extends WebView) is created programatically after the onCreate()
The button and EditTexts are made in the Activity.xml but are brought to front programatically in the Java file.
Why doesnt the above code work?
EDIT - Frame Layout Problem
My XML Code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.example.dencallanan.giftestapp.GifWebView android:id="#+id/GWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_marginBottom="153dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="USERNAME" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_marginTop="58dp"
android:layout_alignTop="#+id/editText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/editText"
android:layout_alignStart="#+id/editText"
android:hint="PASSWORD" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
android:id="#+id/button"
android:layout_below="#+id/editText2"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp" />
</RelativeLayout>
</FrameLayout>
The Error:
You are calling setContentView(R.layout.activity_main) and again later setContentView(view). setContentView will overwrite the layout, this will in effect, replace it with a new layout. I suggest using a FrameLayout in XML file... Webview will be your bottom layer. On top of that Put a Linear/RelativeLayout with the Edittexts and Button... Simple and clean.
You can add your webview in XML like:
<com.package.GifWebView android:id="#+id/GWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
In code, access this as:
GifWebView gWView = (GifWebView) findViewById(R.id.GWebView);
gWView = new GifWebView(this, "file:///android_asset/watg.gif");

Categories

Resources