in my application I have 3 expandableListview as shown here.
<?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:clickable="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="280dp"
android:layout_height="fill_parent"
android:background="#color/filter_items_background"
android:layout_gravity="end"
android:clickable="true"
android:orientation="vertical" >
<!-- Gender -->
<TextView
android:id="#+id/listSelectionHeaderTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/filter_groups_background"
android:gravity="center_vertical"
android:minHeight="#dimen/filterFragment__itemHeight"
android:paddingLeft="20dp"
android:text="#string/filter_interestedin"
android:textColor="#8F8F8F"
android:textSize="20sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/filter_items_background"
android:minHeight="#dimen/filterFragment__itemHeight"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="10dp" >
<TextView
android:id="#+id/men_itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/filter_men"
android:textColor="#android:color/white"
android:textSize="16sp" />
<ToggleButton
android:id="#+id/men_toggleButton"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_switch_drawable"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/filter_items_background"
android:minHeight="#dimen/filterFragment__itemHeight"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="10dp" >
<TextView
android:id="#+id/women_itemText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/filter_women"
android:textColor="#android:color/white"
android:textSize="16sp" />
<ToggleButton
android:id="#+id/women_toggleButton"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/custom_switch_drawable"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<!-- Age -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/filter_groups_background"
android:gravity="center_vertical"
android:minHeight="#dimen/filterFragment__itemHeight"
android:orientation="horizontal"
android:paddingRight="10dp" >
<TextView
android:id="#+id/ageHeaderTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="20dp"
android:text="#string/filter_age"
android:textColor="#8F8F8F"
android:textSize="20sp" />
<TextView
android:id="#+id/ageValuesTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingLeft="20dp"
android:text="Sample"
android:textColor="#android:color/white"
android:textSize="20sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/filter_items_background"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingRight="10dp" >
<SeekBar
android:id="#+id/age_seekBar_from"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:id="#+id/age_seekBar_to"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:background="#000000"
android:groupIndicator="#android:color/transparent"
android:saveEnabled="true" />
<ExpandableListView
android:id="#+id/expandableListView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:background="#000000"
android:groupIndicator="#android:color/transparent"
android:saveEnabled="true" />
<ExpandableListView
android:id="#+id/expandableListView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:background="#000000"
android:groupIndicator="#android:color/transparent"
android:saveEnabled="true" />
</LinearLayout>
</LinearLayout>
My problem is when I open one of expandablelistview the others expandablelistview not showing... I want open one child of expandablelistview and enable scroll and others expandablelistview.
Related
I am having a layout which appears like
I want the page to be scrollabale and list view to add dynamically.
right now when the data is exceeding the page height, I am not able to scroll the page up.
xml is here
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/buttonlayout"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#1274B9"
android:gravity="left|top"
android:orientation="horizontal" >
<Button
android:id="#+id/settings"
android:layout_width="54dp"
android:layout_height="match_parent"
android:background="#drawable/backarrow" />
<ImageView
android:id="#+id/prevMonth"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:clickable="true"
android:onClick="prevDate"
android:src="#drawable/calendar_left_arrow_selector" >
</ImageView>
<TextView
android:id="#+id/currentMonth"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_weight="0.6"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" >
</TextView>
<ImageView
android:id="#+id/nextMonth"
android:layout_width="20sp"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="10sp"
android:clickable="true"
android:onClick="nextDate"
android:src="#drawable/calendar_right_arrow_selector" >
</ImageView>
<Button
android:id="#+id/addEvent"
android:layout_width="54sp"
android:layout_height="match_parent"
android:background="#drawable/check"
android:onClick="gotomealsactivity" />
</LinearLayout>
<!-- Breakfast portion -->
<RelativeLayout
android:id="#+id/relativebreakfastheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/buttonlayout"
android:background="#1274B9" >
<TextView
android:id="#+id/breakfastheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Breakfast"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/totalcalorieheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:gravity="right"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativebreakfastlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativebreakfastheading" >
<ListView
android:id="#+id/listbreakfast"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="#+id/addbreakfast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listbreakfast"
android:layout_centerHorizontal="true"
android:clickable="true"
android:gravity="center"
android:onClick="gotobreakfastactivity"
android:text="Add Food +"
android:textStyle="bold" />
<View
android:id="#+id/view1"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/addbreakfast"
android:background="#ff106510" />
</RelativeLayout>
<!-- Lunch portion -->
<RelativeLayout
android:id="#+id/relativelunchheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativebreakfastlist"
android:background="#1274B9" >
<TextView
android:id="#+id/lunchheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Lunch"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/totalcalorielunchheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:gravity="right"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativelunchlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativelunchheading" >
<ListView
android:id="#+id/listlunch"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="#+id/addlunch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listlunch"
android:layout_centerHorizontal="true"
android:clickable="true"
android:gravity="center"
android:onClick="gotolunchactivity"
android:text="Add Food +"
android:textStyle="bold" />
<View
android:id="#+id/view2"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/addlunch"
android:background="#ff106510" />
</RelativeLayout>
<!-- Dinner portion -->
<RelativeLayout
android:id="#+id/relativedinnerheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativelunchlist"
android:background="#1274B9" >
<TextView
android:id="#+id/dinnerheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Dinner"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/totalcaloriedinnerheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:gravity="right"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativedinnerlist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativedinnerheading" >
<ListView
android:id="#+id/listdinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="#+id/adddinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listdinner"
android:layout_centerHorizontal="true"
android:clickable="true"
android:gravity="center"
android:onClick="gotodinneractivity"
android:text="Add Food +"
android:textStyle="bold" />
<View
android:id="#+id/view3"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/adddinner"
android:background="#ff106510" />
</RelativeLayout>
<!-- Snacks portion -->
<RelativeLayout
android:id="#+id/relativesnacksheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativedinnerlist"
android:background="#1274B9" >
<TextView
android:id="#+id/snacksheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Snacks"
android:textColor="#ffffff"
android:textSize="20sp" />
<TextView
android:id="#+id/totalcaloriesnacksheading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:gravity="right"
android:textColor="#ffffff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativesnackslist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativesnacksheading" >
<ListView
android:id="#+id/listsnacks"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="#+id/addsnacks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/listsnacks"
android:layout_centerHorizontal="true"
android:clickable="true"
android:gravity="center"
android:onClick="gotosnacksactivity"
android:text="Add Food +"
android:textStyle="bold" />
<View
android:id="#+id/view4"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/addsnacks"
android:background="#ff106510" />
</RelativeLayout>
</RelativeLayout>
You can find a screen height and compare it to listBottom - coordinate of some of the ListView's bottom and add new ListViews if needed.
int[] coords = {0,0};
list.getLocationOnScreen(coords);
int listBottom = coords[1] + list.getHeight();
Or problem is that you have no ScrollView in layout?
<?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:background="#00b9e8"
android:orientation="vertical" >
<!-- <include layout="#layout/header" /> -->
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:background="#ffffff"
android:gravity="center"
android:padding="5dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Status"
android:textColor="#0060a4"
android:textSize="#dimen/font_15dp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<ImageView
android:id="#+id/setting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/settings" />
<ImageView
android:id="#+id/searchstatus_imgBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/back_icon" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:background="#drawable/round_bg"
android:padding="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Status"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0060a4"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.65"
android:background="#drawable/round_bg"
android:gravity="center"
android:padding="8dp" >
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:gravity="center"
android:text="Accepted"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0060a4"
android:textSize="20dp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="40dip"
android:layout_height="40dip"
android:paddingLeft="25dip" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="40dp" >
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.35"
android:background="#drawable/round_bg"
android:padding="10dp" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Reason"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#0060a4"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearlayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.65"
android:background="#drawable/round_bg"
android:gravity="center"
android:padding="10dp" >
<TextView
android:id="#+id/reason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#0060a4"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
</LinearLayot>
This is my code i want to add one Footer but i am unable to do this i dont know why this Problem is coming even i have take relative layout then also its not working please tell me how add one footer plz Help
Try this method and better to use relative layout for this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentTop="true"
android:layout_above="#+id/footer"
android:id="#+id/content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999"
android:layout_margin="4dp"
>
<TextView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Content"
android:gravity="center"
android:padding="20dp"
android:textColor="#fff"
/>
</LinearLayout>
<LinearLayout
android:layout_alignParentBottom="true"
android:id="#+id/footer"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FOOTER"
android:gravity="center"
android:padding="20dp"
android:textColor="#fff"
android:background="#666"
/>
</LinearLayout>
</RelativeLayout>
this will give like this .is that you want ?
Hey i wanna make specific single item row for my listView but don't know exacly how to handle it.
i.stack.imgur.com/9fUmX.png
I made something like this using weights on linear layout but it's not working correctly when additional info is too long.
i.stack.imgur.com/uG43j.png
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#55000000" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="10" >
<!-- pomysle jeszcze nad wagami -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2" >
<RelativeLayout
android:layout_width="60dp"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/JsonItemDataNumberOfTheDayFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="21"
android:textColor="#FFF"
android:textSize="15sp" />
<TextView
android:id="#+id/JsonItemDataMonthFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/JsonItemDataNumberOfTheDayFree"
android:layout_centerHorizontal="true"
android:text="CZE"
android:textColor="#FFF"
android:textSize="13sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="7"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- tu nie jestem pewny margin top? -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/JsonItemTitleEventFree"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:singleLine="true"
android:text="Title"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/JsonItemAdditionalInfoFree"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Additional Info"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/JsonItemDateFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:text="Date"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="20dp"
android:layout_height="100dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/JsonItemLogoCategoryFree"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/category_music"
android:scaleType="fitStart" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#55000000"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="2" >
<RelativeLayout
android:layout_width="60dp"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/JsonItemDataNumberOfTheDayFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:text="21"
android:textColor="#FFF"
android:textSize="15sp" />
<TextView
android:id="#+id/JsonItemDataMonthFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/JsonItemDataNumberOfTheDayFree"
android:layout_centerHorizontal="true"
android:text="CZE"
android:textColor="#FFF"
android:textSize="13sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="7"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_gravity="top"
android:id="#+id/JsonItemTitleEventFree"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:singleLine="true"
android:text="Title"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/JsonItemAdditionalInfoFree"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Additional Info"
android:textColor="#android:color/white"
android:textSize="14sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/JsonItemDateFree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="10dp"
android:text="Date"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="20dp"
android:layout_height="100dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/JsonItemLogoCategoryFree"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/category_music"
android:scaleType="fitStart" />
</LinearLayout>
I have included a common layout inside of FragmentActivity.I want to fire onclick event of common layout ToggleButton, inside of fragment class.How can I achieve this?
ToggleButton tbMainLocation = (ToggleButton) getView().findViewById(
R.id.tbMainLocation);
but tbMainLocation always return nullpointerexception
commonlayout:
layout_include.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/rlMainLivTopBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/cyan"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<TextView
android:id="#+id/txtMainBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="<"
android:textColor="#color/white"
android:textSize="30sp"
android:visibility="gone" />
<ImageView
android:id="#+id/imgMainBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/back"
android:visibility="gone" />
<AutoCompleteTextView
android:id="#+id/actv_edt_search_tag_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="5dp"
android:background="#drawable/round_corner_edittext"
android:ems="10"
android:hint="Search by tag"
android:singleLine="true"
android:text=""
android:textSize="15dp"
android:visibility="gone" >
<requestFocus />
</AutoCompleteTextView>
<TextView
android:id="#+id/txtMainTagneme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text=""
android:textColor="#color/white"
android:visibility="gone" />
<TextView
android:id="#+id/txtMainExpertName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:text=""
android:textColor="#color/white"
android:visibility="gone" />
<!--
<ImageView
android:id="#+id/img_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
androImid:background="#drawable/notification" />
-->
<ImageView
android:id="#+id/imgMainExpertEarnByFlight"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/plane_normal"
android:visibility="gone" />
<!--
<ImageView
android:id="#+id/imgMainLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="5dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/imgMainSearch"
android:background="#drawable/location"
android:visibility="visible" />
-->
<ToggleButton
android:id="#+id/tbMainLocation"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:background="#drawable/location_selector"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOff=""
android:textOn="" />
</RelativeLayout>
<LinearLayout
android:id="#+id/llExpertfragmentChooseDistance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rl_liv_top_bar"
android:background="#color/light_cyan"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:visibility="gone" >
<TextView
android:id="#+id/txt_choose_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_marginRight="2dp"
android:maxWidth="60dp"
android:paddingLeft="10dp"
android:text="#string/choose_distance"
android:textSize="10dp" />
<ImageView
android:id="#+id/img_expert_earn_by_walk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/walk_normal" />
<TextView
android:id="#+id/txt_cycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_marginLeft="-2dp"
android:layout_marginRight="-2dp"
android:background="#color/cyan_line"
android:maxHeight="6dp"
android:minWidth="40dp" />
<ImageView
android:id="#+id/img_expert_earn_by_cycle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/cycle_normal" />
<TextView
android:id="#+id/txt_bike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_marginLeft="-2dp"
android:layout_marginRight="-2dp"
android:background="#color/cyan_line"
android:maxHeight="6dp"
android:minWidth="40dp" />
<ImageView
android:id="#+id/img_expert_earn_by_bike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/car_normal" />
<TextView
android:id="#+id/txt_train"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_marginLeft="-2dp"
android:layout_marginRight="-2dp"
android:background="#color/cyan_line"
android:maxHeight="6dp"
android:minWidth="40dp" />
<ImageView
android:id="#+id/img_expert_earn_by_flight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/plane_normal" />
</LinearLayout>
</RelativeLayout>
fragmentactivity.xml
<com.liv.slidingmenu.layout.MainLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- This holds our menu -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_top_menu_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#6d6d6d"
android:orientation="vertical" >
<!-- This acts as Actionbar -->
<LinearLayout
android:id="#+id/ll_prof_img"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#434242" >
<RelativeLayout
android:id="#+id/rr_img_detail"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/img_prof"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/profile_image" />
<TextView
android:id="#+id/txt_expt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/img_leve"
android:layout_marginLeft="35dp"
android:layout_marginTop="35dp"
android:layout_toRightOf="#+id/img_prof"
android:text=""
android:textColor="#ffffff" />
<TextView
android:id="#+id/txt_level"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_below="#+id/txt_expt_name"
android:layout_marginLeft="35dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#+id/img_prof"
android:background="#drawable/level_background"
android:gravity="center_horizontal"
android:paddingTop="5dp"
android:text=""
android:textColor="#d2d2d2" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll_prof_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.6" >
<ListView
android:id="#+id/listview_menu_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#292929"
android:dividerHeight="0.1dip" >
</ListView>
</LinearLayout>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/ll_topbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include
android:id="#+id/topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/layout_include" />
</RelativeLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/ll_topbar" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="-3dp"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<FrameLayout
android:id="#+android:id/realtabcontents"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<!-- android:id="#android:id/tabs" -->
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#f9f9f9"
android:orientation="horizontal" />
</LinearLayout>
</TabHost>
</RelativeLayout>
</com.liv.slidingmenu.layout.MainLayout>
To access views that belong to the activity layout you can use
getActivity().findViewById(R.id.viewid);
Make sure the fragment is attached to the activity and getActivity() does not return null.
Quoting docs
The fragment can access the Activity instance with getActivity() and
easily perform tasks such as find a view in the activity layout
http://developer.android.com/guide/components/fragments.html
When there are many contents in listview, item’s height can full screen or over the screen. The contents is few, in the screen can display many items. How could item of listview adapt the content’s height automatic?
My item layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/main_item_frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp" >
<ImageView
android:id="#+id/imageHead"
android:layout_width="#dimen/wb_head_image"
android:layout_height="#dimen/wb_head_image" />
<ProgressBar
android:id="#+id/main_item_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="false"
android:indeterminateDrawable="#anim/loading"
android:visibility="gone" />
</FrameLayout>
<LinearLayout
android:id="#+id/main_item_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/main_item_frameLayout"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:textSize="18sp" />
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:textColor="#color/yellow"
android:textSize="15sp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/main_item_content_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="20sp"
android:textStyle="bold" />
<GridView
android:id="#+id/main_item_pictures"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:scrollbars="none" >
</GridView>
</LinearLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:textSize="12sp" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/comment"
android:paddingBottom="10dp"
android:src="#drawable/weibo_comment" />
<TextView
android:id="#+id/transmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/imageView4"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:textSize="12sp" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/transmit"
android:paddingBottom="10dp"
android:src="#drawable/weibo_transmit" />
<TextView
android:id="#+id/praise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/imageView3"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:textSize="12sp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/praise"
android:paddingBottom="10dp"
android:src="#drawable/weibo_transmit" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>