i have been trying to create an xml file that integrates a relative layout within the a tabbed layout. Here is my code:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<RelativeLayout
android:id="#+id/simpleMode
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</LinearLayout>
</TabHost>
I am receiving a multitude of errors and i can't seem to find what my problem is:
My errors are Relative Layout must be followed by > or />
and
No recourse found that matches the given name at android:id="#+id/simpleMode
Any help would be appreciated Thank You Very Much!!
Please see you are missing " after android:id="#+id/simpleMode.So your xml file is giving error.Just put it and run
The best way to find these errors easily is to run the XML through an XML validator. The XML validator will tell you exactly whats wrong with your XML.
I generally use W3 Schools XML validator here: http://www.w3schools.com/xml/xml_validator.asp
Related
I'm trying to use the drag/drop functionality from this fine project: https://github.com/bauerca/drag-sort-listview/
First, I've added the library using the instructions on GitHub.
Second, I'm trying to use the XML declaration. This is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.dslv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/header"/>
<com.mobeta.android.dslv.DragSortListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#D9D9D9"
android:dividerHeight="2dp"
android:listSelector="#drawable/list_selector"
dslv:drag_enabled="true"
dslv:drag_scroll_start="0.33"
dslv:drag_start_mode="onDown"/>
</LinearLayout>
But, Eclipse is throwing this error: No resource identifier found for attribute 'drag_enabled' in package 'com.mobeta.android.dslv'; similarly for 'drag_scroll_start' and 'drag_start_mode'.
I'd like to understand on a more general level what I'm doing wrong here. And if anyone can give me specific help for using this library, I'd appreciate that as well.
Since you are refering the attributes fro your library instead of giving the full path of the library give "res-auto"
please see the change
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dslv="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/header"/>
<com.mobeta.android.dslv.DragSortListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#D9D9D9"
android:dividerHeight="2dp"
android:listSelector="#drawable/list_selector"
dslv:drag_enabled="true"
dslv:drag_scroll_start="0.33"
dslv:drag_start_mode="onDown"/>
for reference
I have an image in my main.xml as follows
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="70dp"
android:layout_height="70dp"
android:contentDescription="#string/hello"
android:maxHeight="70dp"
android:maxWidth="70dp" />
but I need to pass it to another xml file. Is this possible?
In your case you are having data reference.
Yes, its possible. Exists a tag called in android that you can "include" another android xml layout in other android xml file. I put a example using your main.xml
In layout2.xml ....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/main"/>
</LinearLayout>
More information about this tag, please check it out in the link below.
http://developer.android.com/training/improving-layouts/reusing-layouts.html
When creating a custom element with attributes in Android I need to put the namespace of the application in the layout.
For example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res/org.example.mypackage"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.example.mypackage.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
Does this also requires that the structure of my project in Eclipse be the same as the name of the Android package as definied in the Manifest - as per the example?
Would this work too:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<org.example.mypackage.MyCustomView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
Its the package name of your application that should be reflected. So its correct to use it as you are doing.
For example:
In xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct the last part org.mycompany.myproduct should be the same as your package name. And you may change xmlns:whatever to anything like xmlns:theblitz but then make sure you do use theblitz as a prefix for your attributes in the xml.
For more info, read this
I have trouble accessing Views from a layout that is included in another layout.
Please take a look at this picture:
http://dl.dropbox.com/u/3473245/layout_includes.png
How do I access the 4 text views programmatically?
Its probably something really simple that I'm missing.
Thank you very much!
You can do as follows:
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include android:id="#+id/item_base_lang" layout="#layout/dictionary_list_item" />
<include android:id="#+id/item_learn_lang" layout="#layout/dictionary_list_item" />
</LinearLayout>
dictionary_list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/dictionary_list_item_text_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/dictionary_list_item_text_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
To set the text programmatically:
((TextView)findViewById(R.id.item_base_lang).findViewById(R.id.dictionary_list_item_text_header)).setText("item_base_lang_header");
((TextView)findViewById(R.id.item_base_lang).findViewById(R.id.dictionary_list_item_text_content)).setText("item_base_lang_content");
((TextView)findViewById(R.id.item_learn_lang).findViewById(R.id.dictionary_list_item_text_header)).setText("item_learn_lang_header");
((TextView)findViewById(R.id.item_learn_lang).findViewById(R.id.dictionary_list_item_text_content)).setText("item_learn_lang_content");
This Android wiki page shows how to use reusable UI components with XML layouts, but it doesn't show how to access nested reusable components from code.
Although it is fairly straightforward, it might be not so clear for those who are pretty new to Android Views.
The following two lines should help you get the languageHeader of both includes. You can do the same for languageText
findViewByid(R.id.activityBaseLangView).findViewById(R.id.languageHeader)
findViewByid(R.id.activityLearnLangView).findViewById(R.id.languageHeader)
I am new to Android and I have been trying to reuse the tutorial on the Android developer website about developing a TabActivity App but, unfortunately, it never worked, even when I constructed it the exact same way as it is described…
Using the debugger it seemed the problem came from the main layout.
-> setContentView(R.layout.main); //After this line the app stops.
Here is my main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
If anyone had the same problem, or if someone have some advices they are welcome :)
Tanks a lot!
Randy
The xml you posted is the same as the TabHost example and there is nothing wrong with it.
There must be something in your code.
Please post the code otherwise we can not help you.