what is wrong in my relativelayout? - android

Hello everybody this is my first post here. I'm begginner in android devlopping.
I'm trying to do a listview and my list item should look likes:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageIcon"
android:layout_width="0dp"
android:layout_weight="2.5"
android:layout_height="120dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:src="#drawable/e3_0_1_184562_20150331100346" />
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="120dp"
android:layout_marginRight="4dp"
android:padding="5dp" >
<RelativeLayout
android:id="#+id/top1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/dscription">
<TextView
android:id="#+id/Product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/Distance"
android:text="#string/shear"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="#+id/Distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/Product"
android:layout_alignParentLeft="true"
android:text="#string/merk"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
<TextView
android:id="#+id/dscription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/thoor"
android:layout_above="#+id/bottom1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#888" />
<RelativeLayout
android:id="#+id/bottom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_alignParentBottom="true">
<TextView
android:id="#+id/name_p"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/price_p"
android:text="#string/sheor"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#888" />
<TextView
android:id="#+id/price_p"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/name_p"
android:layout_alignParentLeft="true"
android:text="#string/mir"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
I need it to looks like that
distance , product
describtion
price , seller
the distance and the product in the first line, distance in left side and product name in right side.
second line , the long desctibtion of the product.
third line (the last), I want to show the price in the left side and the seller in the right side
it doesn't work and it writes:
Exception raised during rendering: Circular dependencies cannot exist in RelativeLayout
Exception details are logged in Window > Show View > Error Log
in the error log it writes 'listitem_deal.xml Circular dependencies cannot exist in RelativeLayout'
thank you and sorry.

what is wrong in my relativelayout?
Answer : Circular dependencies cannot exist in RelativeLayout
Now, what does that mean?
Look at TextView android:id="#+id/Product and TextView android:id="#+id/Distance"
What are you doing is setting up android:layout_toRightOf="#+id/Distance" on Product and android:layout_toLeftOf="#+id/Product" on Distance.
So what Android does is look at Product first and ask, where should I position this? Right of Distance - okay so I'll look at Distance and set Product. But Distance is positioned Left of Product. So I have to look where the Product is... and so on. Do you see how it goes in circle? (there is same error with name_p and price_p)
That's what that error looks for and doesn't allow you to position it this way.
Also, to correct
The preview windows never work well and even if they do they are basically useless.
from comments - the preview feature is working just fine most of the time. This error should be raised on real device as well, not only on IDE.

To create a ListVew you need one ListView item, a structure to contain your data and one adapter to pass these data from the data source to the ListView.
Add the ListView from the layout manager(XML).
Good way to contain the data is to write your custom data class and store it in array or in others kind of structuress.
If your data class just contain one property you want to show use ArrayAdapter else you have to implement your own adapter.
You can use one Loader to query the data from the SqlLite database.
Here you can find more details:
http://www.vogella.com/tutorials/AndroidListView/article.html
http://developer.android.com/guide/topics/ui/layout/listview.html
http://developer.android.com/reference/android/widget/ListView.html

Related

Making the Button's align_parentBottom = "true" when other view's height is not Zero

First the title may look senseless but I don't know how I describe my problem well in the title.
I have a Relative layout which has 2 buttons (Past games and Upcoming Games) and 2 listviews. Whenever a button is pressed the associated listview is collapsed (height will be zero) if it is already expanded or the reverse will happen. ( i used this solution)
Problem:
Everything is fine when I run it on a 5-inch screen phone. Please see the following picture:
[![][2]][2]
But if I run it on a 10-inch tablet it looks like this:
[![][3]][3]
The same will happen when it will run on less than 5-inch phone.
My questions
Do I need to make another layout for the tablet? like in the layout-large folder?
or I can use some event(s) in Jave file that dynamically set the buttons align parent bottom property when the listview is not collapsed.
or it can be fixed in my current XML
Below is the code for that part I am asking for help
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btnPastGames"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:background="#color/YellowColor"
android:text="Past Games"
android:textAllCaps="false"
android:textSize="15sp" />
<ListView
android:id="#+id/lvPastGames"
android:layout_width="match_parent"
android:layout_height="255dp"
android:layout_below="#+id/btnPastGames"
android:layout_centerHorizontal="true"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:layout_marginTop="5dp"
android:divider="#null" />
<Button
android:id="#+id/btnUpcommigGames"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_below="#+id/lvPastGames"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:background="#color/YellowColor"
android:text="Up Coming Games"
android:textAllCaps="false"
android:textSize="15sp" />
<ListView
android:id="#+id/lvUpcomingGames"
android:layout_width="match_parent"
android:layout_height="255dp"
android:layout_below="#+id/btnUpcommigGames"
android:layout_centerHorizontal="true"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:divider="#null" />
</RelativeLayout>
</LinearLayout>
If you guys can give me some advice on making the user interface that will run on all screen sizes and densities I will be very thankful
Thanks to anyone who will help me
You are trying to workaround functionality of ExpandableListView. Look at the following page:
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

how to make list views like google io 2014 app in android?

I want to create a list view layout with a image and title in it. I want a layout like listview in google io 2014 app. It should be a tiled listview with some colour till the image gets loaded, after the image is loaded it should be shown in the upper half of the listview and title should be shown below with some background colour. I am attaching the screenshot of google io app here.
Updated: If somebody can point me some template custom layout for this listview it would be helpful!
Create a custom list with all the needed controls in separate layout and inflate it using a custom adapter you can find a small example here
you could create a custom layout something like 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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:background="#drawable/images"
android:layout_height="match_parent"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#862c10">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:textStyle="bold"
android:text="HTML5 everywhere how and why android users use the webplatform" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Wed 5 2001" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="15sp"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Steven roberts and mark robinson " />
</LinearLayout>
</LinearLayout>
(this should not be the answer, but forgive me I could not add a comment, and actually I hope this will give him the answer).
First of all I guess you didn't get on well with using ListView and Adapter in Android. So I suggest you to read the following article first:
ListView tutorial 1
ListView tutorial 2
They will teach you how to use xml to define your custom row view. Then you will know how to use George Thomas's xml. Try how to implement the getView() method.

Android random user interface behavior

Okay I have a full week of frustration behind me, it is the third time that the layout behaves random.
For example:
<TextView
android:id="#+id/tvGebiedHead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginTop="16dp"
android:text="Geef gebied op"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/lvGebieden"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1" >
</ListView>
produces a result where the listview is displayed on top of the textview (making both items unreadable). The code down here produces the desired result, the listview is rendered under the textview. It is not the eclipse graphical editor, but it happens on a real phone as well. Note that the only difference between the two snippets is the id of the TextView.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginTop="16dp"
android:text="Geef gebied op"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/lvGebieden"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#+id/textView1"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1" >
</ListView>
Earlier this week I had a fight with the layout of four togglebuttons which (all!!) changed size, text align on the button, and even location when I clicked one, while the on and off text was exactly the same. Please tell me I am doing something wrong and android is not broken.
In the example on the top, your ListView's layout_below still refers to #id/textView1 which doesn't exist. It does, however, in your example at the bottom, so the bottom is working. FYI, instead of #+id/textView1 you should use #id\textView1 in the layout_below.

Android ListView Item - Right to Left Animation Menu

In my android application I want the ListView items to move from right to left and show extra options for that row. I don't know how to ask my question so I want to show you the pictures that I took. How can I do that or what it is called ?
This is the first state.
This is the secondstate (after click on the "PLUS" icon on the right side).
This was the final state which shows the extra choices
Is it possible that a ViewPager could be used?
I'm not sure that it would work for only a small part of the screen, but it could be worth a try... :)
More info can be found here (d.android.com)
UPDATE : Thanks to "ToVine", I researched for View Transitions. ViewFlipper suits for what I mentioned belove :). This is my custom listview row's xml.
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="buttonClickHandler" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="buttonClickHandler"
android:src="#android:drawable/btn_star_big_on" />
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="TextView2" />
</ViewFlipper>

Android Developers LinearLayout - I have a repeating list and want 1 button at the bottom of the screen, I keep getting one button per line

I am trying a task that should probably be simple..I want one button at the bottom across the bottom of the screen (floating preferably), while I have a scrollable list above that (I was able to do this in a tutorial with a simple listview and buitton).But, my list is a LinearLayout that I fill with a SimpleCursorAdapter and a viewBinder. Since I am using this LinearLayout I keep getting One button per line item, instead of one at the bottom of the screen. I have tried wrapping it with a table layout, relative layout, using two LinearLayouts, etc. Every time I get one button per line. Is this because of the way I am getting the data with a cursor adapter and filling it into the listview? Do I need to use a "merge" in my xml file? Is there a way to make two xml files and then call them both? Do I need to switch to a ListView or another way of displaying the data? This is my first app that I am trying start to finish on my own, so some of this stuff trips me up. I will include my code for the LinearLayout, please note that this is just the list without my extra button added (i deleted all my failed attempts). So I would be looking to modify the code below to contain one button that floats at the bottom of the screen all the time.
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="290dp"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:hapticFeedbackEnabled="true">
<Button
android:id="#+id/BtnToClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler"
android:drawableLeft="#+drawable/android_button"
android:gravity="left|center_vertical"
android:background="#android:color/transparent"
android:hapticFeedbackEnabled="true"
android:layout_weight=".1">
</Button>
<TextView android:text=""
android:id="#+id/tvViewRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
</TextView>
<TextView android:text="#+id/text11"
android:id="#+id/text11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone">
</TextView>
<TextView
android:id="#+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="left|center_vertical"
android:layout_weight=".20"/>
<TextView
android:id="#+id/text9"
android:layout_column="5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="center|center_vertical"
android:layout_weight=".1"/>
<TextView
android:id="#+id/text10"
android:layout_column="6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:gravity="left|center_vertical"
android:layout_weight=".15"/>
<TextView
android:id="#+id/text12"
android:layout_column="8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:padding="3dip"
android:gravity="left|center_vertical" />
<Button
android:id="#+id/BtnToClick2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="myClickHandler3"
android:gravity="center|center_vertical"
android:background="#+drawable/coup0a"
android:hapticFeedbackEnabled="true"
>
</Button>
Thanks in advance!
-Joe
You need to add the button as a footer or a header according to your needs. You can try this code .The R.layout.header and footer are separate xml layout files which you would have to define.
View header = inflater.inflate(R.layout.header,null);
View footer = inflater.inflate(R.layout.footer,null);
addHeaderView(header);
addFooterView(footer);
You should absolutely use a listview for this job. Listviews are highly optimized for displaying many entries. Just let your activity extend from a ListActivity and create a layout xml file with a listview widget that has the id "#android:id/list" and the listview activity will hook onto that list automatically. You are free to place other widgets in the layout aswell. Here is an example layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<Button
android:id="#+id/chooseOther"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/add_fav"/>
</LinearLayout>
It has a list with a button sitting on the bottom of the screen at all times, even if you have a long list of items.

Categories

Resources