I'm trying to create a button. I've done something like this before, but now I got an error and I' can't find out what is it. I think i've got the problem in the xml file, but can't find it :S
So there is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="115dp"
android:layout_marginTop="80dp"
android:src="#drawable/login_button" />
</RelativeLayout>
I'm trying to implemet some kind of facebook login. I'm using the easyfacebook sdk. So here is the java code where i trying to implement the login button:
http://pastebin.com/brHmJKs1
The messages i get is the following:
W/webcore(29941): Can't get the viewWidth after the first layout
E/SkLayout_wtle(29941): layout error:106 width:0 ellipsizedWidth:0
W/InputManagerService(1171): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#405c4e68
First close your first LinearLayout in last line.Secondly remove RelativeLayout, that is of no use and then try i hope you will get success.
Related
So this is one of my codes and whenever I click run my project fails to build because of the error in this code
android:id="#+id/list_item_forecast_textview" />
for this code it says that there is unexpected end of file, beside the > in the code there is a small red zigzag line going across beside, > in the code. What should I do to fix the small code error?
#Simran:
I think you missing your Opening Tag Like < . Please add this .
<?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" >
<TextView android:id="#+id/list_item_forecast_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello,I am a TextView" />
</LinearLayout>
I think you are new in Android .So before start please read its official documents for xml Write the XML
I'am trying to load a spinner to my layout and keep geting this error:
The following classes could not be found:
- Spinner (Change to android.widget.Spinner, Fix Build Path, Edit XML)
heres my xml:
<?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" >
<Spinner
android:id="#+id/spn_dates"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="displayDatesToSpiner" />
<ListView
android:id="#+id/LST_bought_products"
android:layout_width="match_parent"
android:layout_height="302dp" >
</ListView>
</LinearLayout>
Thanks
This sometimes happens when you rename the standard AppTheme in your android manifest. It will build and deploy just fine, but the xml design editor won't render it.
This is usually because there's an invalid attribute somewhere.
Remove the onClick and it will work.
I want to make a activity like a "Dialog", and I know two ways so far:
Way 1) In Android ApiDemos, it is implemented by adding the attribute to the activity like
android:theme="#android:style/Theme.Dialog">
The result is: the new Activity appears on top of the existing activity, that is what I want.
Way 2) I try to invoke setTheme(android.R.style.Theme_Dialog) in the Activity.onCreate(Bundle) method, and the new activity also appears, but the background is all black. This is not what I want. Code is as below:
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Dialog);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.selecte_date);
Can anybody tell me how to implement the effect by writing Java code?
The easiest way is to add a second layout in you xml which is a overlay of existing one.
then you can set the overlay to visible in your activity. So then you got multiple views in 1 activity.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:background="#android:color/transparent">
<ImageView
android:id="#+id/icon"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:layout_alignParentTop="true"
android:id="#+id/overlay"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/translucent_black"
android:visibility="false" >
</LinearLayout>
</RelativeLayout>
I extended AutoCompleteTextView in android. When I use that new custom AutoCompleteTextView in my XML layout file, Eclipse shows an error saying:
You must specify a valid content view by calling setContentView() before attempting to show the popup. Exception details are logged in Window > Show View > Error Log"`.
Edited XML File is:
<?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" >
<com.mypackage.MyAutoCompleteTextView
android:id="#+id/countries_list_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionHint="Test">
<requestFocus />
</com.mypackage.MyAutoCompleteTextView>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
By simply taking out my custom view from the XML, the layout shows just fine.
Any help will be greatly appreciated, thanks.
I have a class that extends FrameLayout called NoteView.
It is a top level public class.
It works just fine when I'm creating the UI from java code, but I can't figure out how to use it in XML. I tried inserting the fully qualified class name just like I would for a custom view, but I get and exception ClassCastException: android.view.View cannot be cast to android.view.ViewGroup when activity tries to inflate the XML.
I have only been able to find tutorials on Custom Views, not custom viewgroups. What do I need to do to use a NoteView just like I would a FrameLayout in an XML Layout?
For example: This works
<?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">
<test.cjb.sandbox.NoteView
android:id="#+id/noteview"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FF0000"
android:layout_gravity="right">
</test.cjb.sandbox.NoteView>
<Button
android:id="#+id/button"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:text="Sibling Button"/>
</LinearLayout>
But this throws the above exception:
<?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" >
<test.cjb.sandbox.NoteView
android:id="#+id/noteview"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FF0000"
android:layout_gravity="right">
<Button
android:id="#+id/button"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:text="Child Button"/>
</test.cjb.sandbox.NoteView>
</LinearLayout>
In the future, when complaining about exceptions, please consider including the full stack trace, particularly when people ask for the full stack trace, as the full stack trace may contain information that is relevant to giving you an answer. You can get the full stack trace via adb logcat, DDMS, or the DDMS perspective in Eclipse.
Lacking that, all I can do is point you to this sample project that extends a LinearLayout into a custom widget.