I had created an old android project called LinearLayouts and written some code in activity_main.xml under the layout folder. The code ran perfectly fine on the emulator. But now I have edited activity_main.xml and changed the code. The problem is that edited or changed code is not shown on the emulator. Could anybody help me to find solution to this problem. Below is the old code and new code in activity_main.xml. When I run the new code even then the emulator shows the old code output. The new code or edited code output is not shown instead of that it shows the old code output itself.
My previous code of activity_main.xml is:
<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">
<TextView
android:id="#+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Type Here:"
/>
<EditText
android:id="#+id/edittext1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/label"
android:layout_marginTop="10dp"
android:ems="10" >
<requestFocus />
</EditText>
</RelativeLayout>
My new or edited code in activity_main.xml is:
<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"
>
<SlidingDrawer
android:id="#+id/slidingDrawer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Handle" />
<LinearLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</SlidingDrawer>
</RelativeLayout>
Remove all the files from your /bin folder (except for AndroidManifest.xml) in your project root and try again.
Related
Hi I'm following this Simple Parse Messaging App tutorial-https://github.com/codepath/android_guides/wiki/Building-Simple-Chat-Client-with-Parse
And I'm getting an error on this line of code:
tools:context="${relativePackage}.${activityClass}"
This is the whole file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<EditText
android:id="#+id/etMessage"
android:layout_toLeftOf="#+id/btSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/btSend"
android:gravity="top"
android:hint="contribute..."
android:imeOptions="actionSend"/>
<Button
android:id="#+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|right"
android:paddingRight="10dp"
android:layout_alignParentRight="true"
android:text="send"
android:textSize="18sp" >
</Button>
</RelativeLayout>
Replace ${relativePackage} with your package name and replace ${activityClass} with your class name.
For example:
tools:context="whatever.your.package.name.ChatActivity"
I think the tutorial means you should populate relativePackage and activityClass yourself. tools:context must refer to a specific Activity, e.g. com.example.MainActivity.
I'm trying to show a button over a fullscreen image. I tried to use RelativeLayout as shown in this question but I cannot see the Button.
Can someone tell me why this code isn't working?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/pitchImageView"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Apologies if this qualifies as a duplicate question.
EDIT:
Screenshots of the activity.
Android design tab
Emulator at runtime
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
My friend you can use FrameLayout alternatively ,and checkout this site : Android Frame Layout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:src="#drawable/desert_road"
android:scaleType="centerCrop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:src="#drawable/ic_clear_white_24dp"
android:id="#+id/stopwatchButton"
android:layout_gravity="center" />
</FrameLayout>
The Result :
This is a common "problem".
You can try a couple of things:
Invalidate caches and restart Android Studio, or just restart without invalidating
Try the Run -> Clean and rerun option
Or the Build -> Clean project or Build -> Rebuild Project options
When you are done, run the project again.
Well I got it working, I can't exactly explain what fixed it but these are the steps I took:
Utilised a content and activity split. (to get an example of this create a basic activity in android studio).
I deleted other versions of the layout files in the version compatible folders (such as "layout-v24").
I also used "Clean" and "Rebuild" project options whenever I made a change to my code.
activity xml file:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true">
<include layout="#layout/content_record_game"/>
</android.support.design.widget.CoordinatorLayout>
This is my content.xml file
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/pitchImageView"
android:contentDescription="#string/image_of_a_gaa_pitch"
android:src="#drawable/gaa_pitch"
android:scaleType="centerCrop"
android:cropToPadding="false"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/start"
android:id="#+id/stopwatchButton"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
As the title say , i was using only one xml file on my project activity_maps ,
and everything was working fine , but after adding info_window.xml , the symbol R became red and i don't know why , i tried rebuilding project and nothing happened.
This is my activity_maps.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"
tools:context=".MapActivity" >
<fragment 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:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
This is my info_window.xml :
<?xml version="1.0" encoding="utf-8"?>
<linearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sefleticon"/>
<linearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#id/tv_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold" />
<TextView
android:id="#id/tv_men"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#id/tv_women"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#id/tv_like"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</linearLayout>
</linearLayout>
The both of the xml files are in res/layout
Change id="#id" with id="#+id" like this:
<TextView
android:id="#+id/tv_place" <!--add +id-->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold" />
edit:
and like Nikhil Verma said, change LinearLayout with upcase on two places.
In your second Xml to :
Change linearLayout to LinearLayout
And in your TextView's change android:id="#id/your_id" to android:id="#+id/your_id"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
<AnalogClock
android:id="#+id/analogClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="290dp" />
<TextClock
android:id="#+id/textClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="146dp"
android:text="#+id/textclock"
android:textColor="#FFFFFF"
android:textSize="100sp" />
</RelativeLayout>
Can I have some help on this I'm really confused would really appreciate some advice. I was just cleaning up my code when this error appeared. I have no idea on how to fix
The error comes because you didn't close RelativeLayout tag in your xml file,so add </RelativeLayout>at the end of xml file.
You don't need to add two relative layout where one parent layout is useless
So simply replace in your code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${packageName}.${activityClass}" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context=".MainActivity" >
with
<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="#drawable/bg"
tools:context=".MainActivity" >
Second Option is
Remove your xml code and saved the xml file. After that,replace it with the above code and save. The error will be gone. It is probably a remnant from the time when "automatically build project" enabled.
I have this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:text="Disable Filter" android:background="#drawable/buttons" style="#style/ButtonText" android:layout_weight="25" />
<ImageView android:id="#+id/imageFilter" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="75" />
<HorizontalScrollView android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:id="#+id/horizontal" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
As soon as I add android:id="#+id/btnFilterPreview" to the Button my app stops working. Why is that?
In Netbeans to solve the issue, Right click on the Project and and chose: Clean and Build
Clean Build your project so that all id is regenerate and application will find reference of new ids.
This is a Same code of you . Running Perfect Without any changes.
I had just Clean & Re-Build Project Nothing else .
Try it.
<Button
android:id="#+id/btnFilterPreview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="25"
android:background="#drawable/ic_action_search"
android:text="Disable Filter" />
<ImageView
android:id="#+id/imageFilter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="75" />
<LinearLayout
android:id="#+id/horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="25"
android:orientation="horizontal" >
</LinearLayout>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</HorizontalScrollView>
It may also be caused Android automatically adds android.R in its header file remove it
and then Build Project Again
Besides Clean and Build, make sure you do not have duplicate IDs.
Say you have another ImageView with the same ID, it could crash when some code like
(Button)findViewById(R.id.btnFilterPreview)
is executed.