adding an image inside navigation drawer - android - java

I want to add an image with a link inside a navigation drawer,
is it possible to add an image inside navigation drawer ?
I added coding like this but it is showing below error please check
ImageView imageView6 = (ImageView) findViewById(R.id.imageView6);
imageView6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
specialOffers = (WebView) findViewById(R.id.specialOffers);
specialOffers.getSettings().setJavaScriptEnabled(true);
specialOffers.loadUrl("http://www.fbcdubai.com/membership/offres-privileges/");
}
});
}

open nav_header_layout_name.xml and add image view say (ProfileImage)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_head"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/home_profile_image"
android:layout_width="120dp"
android:layout_height="170dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:layout_gravity="center"
android:src="#drawable/profile_image"/>
</LinearLayout>
to access this image view from the java class:
- NavigationView navigationView = findViewById(R.id.nav_view_id);
- View hView = navigationView.getHeaderView(0);
- ImageView ProfileImage = (ImageViwe) hView.findViewById(R.id.home_profile_image);

create a listView inside the drawer navigation then create a custom item with image view finally attach it to a custom adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/***"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/***"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/****"
android:id="#+id/nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/***"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
</android.support.design.widget.NavigationView>
cust item
enter code 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="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#00000000">
<ImageView
android:id="#+id/****"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/****"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

Certainly you can do this by setting a listener to your image inside the getView method of the adapter
discu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//put here your code
});

Related

onCreateOptionsMenu not called in fragment when using fragment transaction. Will appear when fragment is included in XML

I have a menu created that I am trying to display in my Fragment. Everything works well if the fragment is included in the activities xml layout file. But if I try to add the fragment to the frameLayout via fragment transaction without changing any other implementation the menu will not appear.
Activity
Fragment frag = Fragment.newInstance();
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame, frag)
.commit();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Fragment
#Override
public void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
#Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater
inflater) {
inflater.inflate(R.menu.menu, menu);
}
Activity 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:orientation="vertical"
>
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_weight=".60"
android:layout_height="0dp">
<!--<fragment-->
<!--android:id="#+id/frag"-->
<!--android:name="name"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent">-->
<!--</fragment>-->
</FrameLayout>
<FrameLayout
android:id="#+id/controls_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="#+id/controls"
android:name="ControlsFrag"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout>
Fragment Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/softGray"
android:clickable="true"
android:focusable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:theme="#style/AppTheme.AppBarOverlay"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:collapsedTitleTextAppearance="#style/collapsedText"
app:contentScrim="#color/softGray"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleTextAppearance="#style/expandedText"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="#string/action_groups">
<android.support.v7.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.5"
app:srcCompat="#drawable/ic_skyscraper" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="#+id/main_groups_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Menu Layout
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<item
android:id="#+id/search"
android:enabled="true"
android:icon="#drawable/ic_search_black_24dp"
android:title="#string/string"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/edit"
android:enabled="true"
android:icon="#drawable/ic_edit_black_alpha_24dp"
android:title="#string/string"
app:showAsAction="ifRoom"
/>
<item
android:id="#+id/add"
android:enabled="true"
android:icon="#drawable/ic_add_black_24dp"
android:title="#string/string"
app:showAsAction="ifRoom"
/>
</menu>

SwipeRefreshLayout is Not Working On Real Devices Only Works on Emulator

activity_maian.xml
This Code Working Perfectly On Emulator But not Working on Real Devices And i can't Scroll Down Because of SwipeRefreshLayout Always comes in Middle when i am Scrolling Please Help me with this Problem
Thanks in Advance!!!
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/mains">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipe">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
tools:layout_editor_absoluteX="-21dp"
tools:layout_editor_absoluteY="-2dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#menu/drawer_view">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
This is MainActivity I gave a normal swipe refresh layout code which is working in emulator but not in real devices..
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
LoadWed();
}
});
LoadWed();
public void LoadWed(){
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
swipe.setRefreshing(true);
webView.loadUrl("https://localhost/admin");
webView.getSettings().setDomStorageEnabled(true);
swipe.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
}
Added FrameLayout as a first child of DrawerLayout. And added TextView, ProgressBar, SwipeRefreshLayout as a child of that FrameLayout and now it works as expected.
Like This
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="#+id/mains">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipe">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
tools:layout_editor_absoluteX="-21dp"
tools:layout_editor_absoluteY="-2dp" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#menu/drawer_view"></android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Unable to See ImageView with RecyclerView in a RelativeLayout

I'm attempting to create a simple image gallery with the thumbnails shown at the bottom using a RecyclerView and the large/detailed photo shown above it in an ImageView.
The problem is - the RecyclerView with the thumbnails is shown and created - however the large/detailed image is never shown, even when hardcoding it's background. I believe this to be an XML related issue - but I cannot seem to spot the problem.
Any suggestions are appreciated.
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#color/black_color"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="#+id/detail_photo"
android:background="#drawable/mms_img1"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/detail_photo"
android:background="#color/black_color" />
</RelativeLayout>
Java:
public class SpaceGalleryActivity extends AppCompatActivity {
ImageView mImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_space_gallery);
mImageView = (ImageView) findViewById(R.id.detail_photo);
Glide.with(this)
.load("http://i.imgur.com/zuG2bGQ.jpg")
.placeholder(R.drawable.ic_launcher)
.into(mImageView);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv_images);
recyclerView.setHasFixedSize(true);
// recyclerView.setLayoutManager(layoutManager);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
SpaceGalleryActivity.ImageGalleryAdapter adapter = new SpaceGalleryActivity.ImageGalleryAdapter(this, SpacePhoto.getSpacePhotos());
recyclerView.setAdapter(adapter);
}
....
the problem is that you are setting RecyclerView to match_parent.which overlaps your ImageView
so change your layout to
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="#drawable/mms_img1"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="28dp"
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/detail_photo"
android:layout_below="#id/detail_photo"
android:background="#color/black_color"
/>
</RelativeLayout>
It would work for you.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black">
<ImageView
android:id="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="#drawable/placeholder"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/detail_photo"
android:background="#color/red_500" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="#+id/detail_photo"
android:background="#mipmap/ic_launcher"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_below="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black_color" />
</RelativeLayout>
Changing from a RelativeLayout to a LinearLayout resolved the issue.

Android: Order of addition of fragments

I have this code:
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener()
{
//Se aggiungo un fragment A al container X e aggiungo il fragment B allo stesso container, il fragment B andrĂ  sopra
//il fragment A
#Override
public void onClick(View v)
{
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if(ko==0)
{
MyFragment fragment = MyFragment.createFragment(0);
fragmentTransaction.add(R.id.formazione3,fragment);
ko++;
}
else if(ko==1)
{
MyFragment fragment = MyFragment.createFragment(1);
fragmentTransaction.add(R.id.formazione2,fragment);
ko++;
}
else if(ko==2)
{
MyFragment fragment = MyFragment.createFragment(2);
fragmentTransaction.add(R.id.moduli2,fragment);
ko++;
}
else if(ko==3)
{
MyFragment fragment = MyFragment.createFragment(1);
fragmentTransaction.add(R.id.moduli5,fragment);
}
fragmentTransaction.commit();
}
});
Well, I'm experiencing the order of addition of fragments. I have 4 fragments and I don't understand why some fragments, when I add them, go under the bigger fragment, while other ones go on the bigger fragment in their container.
formazione3>formazione2 (formazione2 is contained in formazione3)
moduli2>moduli5 (moduli5 is contained in moduli2, moduli2 is contained in part in formazione3)
When I add the second fragment, it doesn't show, I think that it goes under the previous fragment, so it goes under the bigger. When I add the third fragment, it goes in part under the first fragment, the first is bigger. When I add the fourth fragment, it goes on the third, but the third is bigger than the fourth and above all the the fourth is contained in the third. How does it work? I don't understand at all!
This is the layout:
<RelativeLayout 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"
tools:context="com.example.utente.fantacalcio.FormazioniActivity"
android:weightSum="1"
android:id="#+id/activity_formazioni_layout">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:id="#+id/button2" />
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/button" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="107dp"
android:layout_height="match_parent"
android:id="#+id/moduli">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="92dp"
android:layout_height="match_parent"
android:id="#+id/moduli1">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione1">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="71dp"
android:layout_height="match_parent"
android:id="#+id/moduli2">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione2">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="51dp"
android:layout_height="match_parent"
android:id="#+id/moduli3">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione3">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="29dp"
android:layout_height="match_parent"
android:id="#+id/moduli4">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione4">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="11dp"
android:layout_height="match_parent"
android:id="#+id/moduli5">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione5">
</RelativeLayout>
</LinearLayout>
Your parent layout is a RelativeLayout , the default behavior for this layout is that first child view is under the last child view.
In your xml this child :
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="51dp"
android:layout_height="match_parent"
android:id="#+id/moduli3">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione3">
</RelativeLayout>
</LinearLayout>
is under this child view :
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="71dp"
android:layout_height="match_parent"
android:id="#+id/moduli2">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/formazione2">
</RelativeLayout>
</LinearLayout>
so when the views are inflating , this is the opposite formazione3 is over formazione2.
Moreover your LinearLayout have these attributes :
android:layout_width="match_parent"
android:layout_height="match_parent"
so they take all the place available.
Try to set fixe size in dp instead of match_parent to see what's really happen.
Hope this helps.
Sorry for my poor english.

Android tabhost issue...code included

I am getting the following error when I try to launch an activity containing a tabhost.
08-25 16:51:42.551:
ERROR/AndroidRuntime(27863):
java.lang.RuntimeException: Unable to
start activity
ComponentInfo{com.paratransit/com.paratransit.jobDialog}:
java.lang.RuntimeException: Could not
create tab content because could not
find view with id 2131165185
This is my code. Can anyone help?
Java
public Class jobDialog extends TabActivity {
TabHost tabs;
int jobCurrentTab = -1;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
setContentView(R.layout.job_dialog);
tabs = getTabHost();
tabs.setup();
setupTabs();
}
public void setupTabs()
{
TabSpec tspec1 = tabs.newTabSpec("First Tab");
tspec1.setIndicator("Summary", getResources().getDrawable(R.drawable.tab_main)).setContent(R.id.jobDetail1);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec("Second Tab");
tspec2.setIndicator("Details", getResources().getDrawable(R.drawable.tab_message)).setContent(R.id.jobDetail2);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec("Third Tab");
tspec3.setIndicator("Notes", getResources().getDrawable(R.drawable.tab_jobs)).setContent(R.id.jobDetail3);
tabs.addTab(tspec3);
XML
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<LinearLayout
android:id="#+id/jobDetail1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/jobDetail2"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/jobDetail3"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</LinearLayout>
</LinearLayout>
</TabHost>
I think the 3 linear layouts, jobDetail1->3 should be within the FrameLayout xml element. The point of the FrameLayout is that all of the views are on top of each other, and thus the tab manager can decide which view to show.
I think you're getting this error because you are not including the LinearLayout inside the FrameLayout, besides I think you need to put some element view inside the LinearLayout's.
Something like this
<?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"
android:id="#+id/establecimientoView">
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs" />
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabcontent" >
<LinearLayout
android:id="#+id/tabIdEst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/identificacion_establecimiento"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabRefGeo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/referencia_geografica"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabUbicEstablecimiento"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/ubicacion_establecimiento"/>
</LinearLayout>
<LinearLayout
android:id="#+id/tabVialidades"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="#layout/entre_vialidades"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

Categories