i have this pager in the layout and i tried to setVisibility for the pager and the linear layout based on condition , but its not working i search in the internet and all have the same answer, any idea ?
this is the xml
<LinearLayout
android:orientation="vertical"
android:id="#+id/error_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:visibility="visible">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:srcCompat="#mipmap/ic_launcher"
android:id="#+id/error_image_view"
android:layout_weight="0.59" />
<TextView
android:text="This Screen Is Not Active"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/error_text_view"
android:layout_weight="0.59" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"></android.support.v4.view.ViewPager>
and this is the main activity
ViewPager imagePager;
LinearLayout errorLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_pager);
//views
errorLayout = (LinearLayout) findViewById(R.id.error_linear_layout);
imagePager = (ViewPager) findViewById(R.id.pager);
IsActive();
}
public void IsActive()
{
String x = "x";
if (x=="x")
{
imagePager.setVisibility(View.VISIBLE);
errorLayout.setVisibility(View.INVISIBLE);
}else
{
imagePager.setVisibility(View.INVISIBLE);
errorLayout.setVisibility(View.VISIBLE);
}
}
Maybe the error isnt that the view isnt INVISIBLE, but that:
x can never equal "x". variable X is a reference, not the actual representation of it.
Use:
if(x.equals("x")) instead.
Related
EDITED
The examples in google searches and the android documentation are basic, and my question is more complex.
What I do not know, is how to put multiple components together and turn it into a single component. CardView + LinearLayout + TextView + ImageView = Custom View.
If I have a basic example, of cardview with at least one button and a space for external content. It would be enough for me to figure out how to do the rest. This within the cardview extension class, because I also do not know how the extension will understand where to create the components
EDITED 2
Example
QUESTION
I was trying to create a method of using Cardview with an expandable button, and I was able to do this in XML. But I wanted to be able to create a library so I could reuse it in other cases.
I'll show you the source code of what I did.
Layout XML
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/cwlltitulobtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#### TITLE OF BUTTON ####"
android:textSize="18sp"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imgarrowdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="visible"
app:srcCompat="#drawable/ic_keyboard_arrow_down_black_24dp" />
<ImageView
android:id="#+id/imgarrowup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="gone"
app:srcCompat="#drawable/ic_keyboard_arrow_up_black_24dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cwllconteudo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:visibility="gone">
<!-- ########################################
######## CARDVIEW CONTENT HERE #########
########################################-->
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Java code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.cwlltitulobtn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CVOpenCloseBTN();
}
});
}
public void CVOpenCloseBTN(){
ImageView arrowdown = (ImageView) findViewById(R.id.cvimgarrowdown);
ImageView arrowup = (ImageView) findViewById(R.id.cvimgarrowup);
LinearLayout pagecontent = (LinearLayout) findViewById(R.id.cwllconteudo);
if (conteudopage .getVisibility() == View.GONE) {
// it's collapsed - expand it
pagecontent.setVisibility(View.VISIBLE);
arrowdown.setVisibility(View.GONE);
arrowup.setVisibility(View.VISIBLE);
} else {
// it's expanded - collapse it
pagecontent.setVisibility(View.GONE);
arrowdown.setVisibility(View.VISIBLE);
arrowup.setVisibility(View.GONE);
}
}
}
My idea is that I can transform all this part of the xml and java code to be used in this way and faster, than to have to always repeat again:
<br.com.samantabiblioteca.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:titulo="#### TITLE OF BUTTON ####">
<!-- ########################################
######### CARDVIEW CONTENT HERE ########
########################################-->
</br.com.samantabiblioteca.CardView>
Is it possible to do this?
I have ControllerFragment which has 3 child fragments. Children fragments change are provided in the tabLayout via ViewPager. Unsend Apple and Banana badge count are computable variable values. unSendAppleCountTxtView and unSendBananaCountTxtView are changed according to these variable values.
My function is running main Thread.
Tried methods:
I have controlled null check and textView isn't null
setUnSendAppleCount function is taken in these threads (runOnUIThread, new Handler(), new Handler(Looper.getMainLooper()))
I have tried AsyncTask and not working setView and setText in postExecute too.
And finally I scan all related questions and tried.
All methods didn't work. TextView is empty value.
public class ControllerFragment extends Fragment {
#Override
public View onCreateView(#NonNull LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.controller_fragment, viewGroup, false);
tabs = ViewUtil.findById(rootView, R.id.tabs);
viewPager = ViewUtil.findById(rootView, R.id.controllerViewPager);
setFragments();
setupViewPager(viewPager);
tabs.setupWithViewPager(viewPager);
setupTabIcons(viewGroup);
return rootView;
}
private void setupTabIcons(ViewGroup viewGroup) {
LinearLayout appleListTab = (LinearLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text_and_badge, viewGroup, false);
RelativeLayout pearListTab = (RelativeLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text, viewGroup, false);
LinearLayout bananaListTab = (LinearLayout) LayoutInflater.from(MyApplication.getContext()).inflate(R.layout.tab_title_text_and_badge, viewGroup, false);
unSendAppleCountTxtView = appleListTab.findViewById(R.id.badgeView);
unSendBananaCountTxtView = bananaListTab.findViewById(R.id.badgeView);
TextView appleTextView = appleListTab.findViewById(R.id.textView);
TextView pearTextView = pearListTab.findViewById(R.id.textView);
TextView bananaTextView = bananaListTab.findViewById(R.id.textView);
setUnSendAppleCount(2); //....this function is not working
setUnSendBananaCount(2); //.....this function is not working
bananaTextView.setText(getString(R.string.bananas));
tabs.getTabAt(0).setCustomView(bananaListTab);
appleTextView.setText(getString(R.string.apples));
tabs.getTabAt(1).setCustomView(appleListTab);
pearTextView.setText(getString(R.string.pears));
tabs.getTabAt(2).setCustomView(pearListTab);
}
private void setupViewPager(ViewPager viewPager) {
TabsViewPagerAdapter adapter = new TabsViewPagerAdapter(getFragmentManager());
adapter.addFrag(bananaFragment, getString(R.string.bananas));
adapter.addFrag(appleFragment, getString(R.string.apples));
adapter.addFrag(pearFragment, getString(R.string.pears));
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(1);
}
private void setUnSendAppleCount(int unSendCount) {
if (unSendAppleCountTxtView != null) {
if (unSendCount > 0) {
unSendAppleCountTxtView.setVisibility(View.VISIBLE);
unSendAppleCountTxtView.setText(String.format(getMyLocale(), "%d", unSendCount));
} else {
unSendAppleCountTxtView.setVisibility(View.GONE);
}
}
}
}
controller_fragment xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/tab_unpressed_color">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/tabColor" />
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/controllerViewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/app_bar_layout" />
</RelativeLayout>
tab_title_text_and_badge.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_gravity="center"
android:gravity="center"
android:weightSum="2"
android:orientation="horizontal"
tools:background="#color/Black">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:layout_gravity="center"
android:maxLines="1"
android:layout_weight="1.99"
android:textColor="#color/white"
android:textSize="#dimen/infoTitle"/>
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:visibility="gone"
tools:text="11"
tools:visibility="visible" />
</LinearLayout>
Please help me
try to setVisibility android:visibility="visible" or android:visibility="invisible" delete gone attribute it remove TextView.
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:visibility="visible" //change here
tools:text="11"
tools:visibility="visible" />
Please use android:text instead tools:text
tools:text="text" is used only for Android Studio layout preview (wont be visible while running the app)
android:text="text" is used to set text to a a layout element, which you can see when the app is run
Try using the below xml,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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:layout_gravity="center"
android:gravity="center"
android:weightSum="2"
android:orientation="horizontal"
android:background="#color/Black">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:gravity="center"
android:layout_gravity="center"
android:maxLines="1"
android:layout_weight="1.99"
android:textColor="#color/white"
android:textSize="#dimen/infoTitle"/>
<TextView
android:id="#+id/badgeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginEnd="1dp"
android:layout_marginRight="1dp"
android:layout_weight="0.01"
android:background="#drawable/tab_controller_badge"
android:gravity="center"
android:textColor="#color/white"
android:textSize="#dimen/miniTextSize"
android:text="11"/>
</LinearLayout>
Hope it helps!
I guess different thread problem. I have tried that eventBus for activity passing data to fragment and it solved.
ControllerFragment(){
#Override
public void onStart() {
super.onStart();
if (!EventBus.getDefault().isRegistered(this)) EventBus.getDefault().register(this);
}
#Override
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
}
#Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMain(ControllerEvent event) {
if (event.getSelectedEventType() == ControllerEvent.tabControllerEventTypes.refreshCount.ordinal()) {
setUnSendAppleCount(event.getAppleCount());
}
}
}
I have a TabLayout in my app and it holds custom views:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="horizontal">
<com.myproject.app.utils.commons.IconImageView
android:id="#android:id/icon"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginRight="14dp"
android:layout_marginEnd="14dp"
app:iconStateListColor="#color/color_order_tab"/>
<TextView
android:id="#android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/color_order_tab"
android:textSize="14sp"
android:fontFamily="sans-serif-medium"/>
</LinearLayout>
</RelativeLayout>
I want to show text on the Tab only if it selected - already done - and resize these tabs dynamically, is there any way to do that?
If I use app:tabMode="fixed" tabs don't resize, if I use app:tabMode="scrollable" my tabs are always on the left of my screen. If I do android:layout_width="wrap_content" and android:layout_gravity="center_horizontal" - TabLayout doesn't fill the screen..
So I need to:
Resize tabs when text appears or disappears;
Tabs should fill the screen in any case.
First of all, you cannot obtain all the desired feature on using fixed mode. As in fixed mode, you cannot resize your tabs.
You need to use scrollable mode in order to resize the tabs.
If I do android:layout_width="wrap_content" and
android:layout_gravity="center_horizontal" - TabLayout doesn't fill
the screen
You can set a parent container and set a background so that it gives you a feel of a tab layout with full device width.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_orange_light">
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
app:tabGravity="center"
app:tabMode="scrollable" />
</FrameLayout>
Then, you can add the tabs i.e. your custom tabs in your tab layout and after that, you can add addOnTabSelectedListener to get the desired results:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
View view = getLayoutInflater().inflate(R.layout.custom_tab, null);
((TextView) view.findViewById(R.id.text)).setText("large text one");
View view1 = getLayoutInflater().inflate(R.layout.custom_tab, null);
((TextView) view1.findViewById(R.id.text)).setText("1");
View view2 = getLayoutInflater().inflate(R.layout.custom_tab, null);
((TextView) view2.findViewById(R.id.text)).setText("Large Text Text Text");
View view3 = getLayoutInflater().inflate(R.layout.custom_tab, null);
((TextView) view3.findViewById(R.id.text)).setText("One");
View view4 = getLayoutInflater().inflate(R.layout.custom_tab, null);
((TextView) view4.findViewById(R.id.text)).setText("Another large text");
mBinding.tabs.addTab(mBinding.tabs.newTab().setCustomView(view));
mBinding.tabs.addTab(mBinding.tabs.newTab().setCustomView(view1));
mBinding.tabs.addTab(mBinding.tabs.newTab().setCustomView(view2));
mBinding.tabs.addTab(mBinding.tabs.newTab().setCustomView(view3));
mBinding.tabs.addTab(mBinding.tabs.newTab().setCustomView(view4));
mBinding.tabs.getTabAt(0).getCustomView().findViewById(R.id.text).setVisibility(View.VISIBLE);
mBinding.tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
tab.getCustomView().findViewById(R.id.text).setVisibility(View.VISIBLE);
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
tab.getCustomView().findViewById(R.id.text).setVisibility(View.GONE);
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
As you can see the tabs are now resizable and only text on the selected tab is visible. Hope that help
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="#android:color/white"
app:tabTextAppearance="?attr/tabTextAppearance"
app:tabMode="scrollable" />
I have a navigation Drawer, the left side is the left navigation drawer, containing TextView "detailsTxt". This contains dynamic text, and I want the navigation drawer to be resized to fit the TextView when the user opens the drawer.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout mlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/app_bg">
<LinearLayout
android:id="#+id/topNavigator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/toolbar_white_space">
<TextView
android:id="#+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_centerVertical="true"
android:background="#android:color/transparent"
android:text="Ayman Salah"
android:textColor="#android:color/white"
android:textSize="16sp"
android:textStyle="bold|italic"
android:layout_marginTop="15dp" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
<!-- drawer layout -->
<LinearLayout
android:layout_width="450dp"
android:id="#+id/leftBar"
android:layout_gravity="start"
android:layout_height="fill_parent"
android:gravity="start|left">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/nbackground">
<TextView
android:id="#+id/detailsTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="20sp"
android:text="string/sample_details"
android:textColor="#android:color/widget_edittext_dark" />
</RelativeLayout>
</LinearLayout>
Add listeners for Drawer
Open/Close events
and
Add this code in onDrawerOpen(), found from this answer :
LinearLayout mDrawerListView = (LinearLayout) findViewById(R.id.leftBar);
mDrawerListView.post(new Runnable() {
#Override
public void run() {
DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) mDrawerListView.getLayoutParams();
params.width = (int) 100; // for example
mDrawerListView.setLayoutParams(params);
}
});
and set layout_width="0dp" in xml file
Try initializing the Navigation Draw with a zero width, i.e. android:layout_width="0dp", and then execute the snippet below in your onCreate(Bundle savedInstanceState).
// Programatically assigns a custom width to a DrawerLayout.
this.getDrawerLayout().addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
/** Fire-and-forget programmatic width implementation for the DrawerLayout. */
#Override public final void onDrawerSlide(final View pDrawerView, final float pSlideOffset) {
// Recalculate the new LayoutParams.
pDrawerView.setLayoutParams(this.getLayoutParams((DrawerLayout.LayoutParams)pDrawerView.getLayoutParams()));
// Stop listening for future events, once we've configured the size once. (We know the DrawerLayout is the direct parent of the DrawerView.)
((DrawerLayout)pDrawerView.getParent()).removeDrawerListener(this);
}
/** A method used to define the new LayoutParams of the DrawerView. */
private final DrawerLayout.LayoutParams getLayoutParams(final DrawerLayout.LayoutParams pLayoutParams) {
/** TODO: Compute your width here! (i.e pLayoutParams.width = X) **/
// Return the LayoutParams.
return pLayoutParams;
}
});
Have a DashBoardActivity that extends a custom MainActivity but i get NullPointerException when trying to access certain views from the DashBoardActivity. Any idea why this could be happening or something am not seeing here?. Thanks
MainActivity:
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.dashboard_layout);
linearlayout = (LinearLayout)findViewById(R.id.footer_container_id);
actionlayout = (LinearLayout)findViewById(R.id.actionbar_container_id);
mainboard = (ImageView)findViewById(R.id.image_dashboard_id);
dashboard = (ImageView)findViewById(R.id.image_comparison_id);
graph = (ImageView)findViewById(R.id.image_graph_id);
contact = (ImageView)findViewById(R.id.image_contact_id);
actionbar = getSupportActionBar();
actionbarView = getLayoutInflater().inflate(R.layout.actionbar, null);
actionbar.setCustomView(actionbarView, new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
}
public void setSelectedDashBoard(){
mainboard.setSelected(true);
}
DashBoardActivity:
public class DashBoardActivity extends MainActivity implements OnClickListener {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
int orientation = getResources().getConfiguration().orientation;
sessionmanager = new SessionManager(this);
prefs = getSharedPreferences(PREFS_NAME,0);
String cached_username = prefs.getString(USERNAME, "");
mainboard.setSelected(true); // NullPointerException here.
dashboard_layout.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="match_parent"
android:orientation="vertical" >
<LinearLayout
android:orientation="horizontal"
android:id="#+id/footer_container_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<include layout="#layout/footer"></include>
</LinearLayout>
<FrameLayout
android:id="#+id/dashboard_fragment_container_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/footer_container_id"
android:layout_alignParentTop="true">
</FrameLayout>
</RelativeLayout>
part of footer.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_footer_id" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:background="#292929" android:orientation="horizontal">
<LinearLayout android:id="#+id/ytd_container_id"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:orientation="vertical">
<ImageView android:id="#+id/image_dashboard_id"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center" android:src="#drawable/footer_icons_ytd" />
<TextView android:id="#+id/ytd_text_id" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_gravity="center"
android:layout_marginBottom="5dp" android:layout_marginLeft="5dp"
android:clickable="false" android:paddingLeft="10dp" android:text="Year to Date"
android:textColor="#FFFFFF" android:textSize="10sp">
</TextView>
"
</LinearLayout>
Update
if i use the method setSelectedDashBoard() instead, which i just added from the MainActivity class, i don't get the NullPointerException. don't understand it..
dashboard = (ImageView)findViewById(R.id.image_comparison_id);
the only reason for dashboard to be null is R.id.image_comparison_id does not belongs to R.layout.dashboard_layout
It looks like a typical error of subclass member variable obscuration. You should check if you re-declared the variable dashboard in DashBoardActivity. The subclass is just substituting the inherited variable with a local one which is not initialised.
It is the character " , unless it is a typo.
</TextView>
**"**
</LinearLayout>