2 Replies - 346 Views - Last Post: 19 December 2018 - 07:26 PM

#1 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

'Resource.Id' does not contain a definition for 'TabHost&#

Posted 11 December 2018 - 07:52 PM

I need to FindViewById<> on TabHost in Xamarin; but every time that I try to use the method outside MainActivity, I'm getting this error:

'Resource.Id' does not contain a definition for 'TabHost'

Does anyone know how to access the TabHost from outside MainActivity ??? Here's what works inside MainActivity:

            TabHost tabHost = FindViewById<TabHost>(Android.Resource.Id.TabHost);


Here's the code I'm trying to use in a LongClickListener.. but it doesn't matter where I try to reference TabHost; if it's not inside MainActivity, Resource does not contain definition or object reference not set to instance of an object.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Webkit;
using Android.Widget;
using com.BitChute;
using static Android.Views.View;

namespace com.BitChute.Activities
{
    public class WhatsOnLongClickListener : Java.Lang.Object, IOnLongClickListener
    {

        private MainActivity _mainActivity;

        private TabHost tabHost;

        public WhatsOnLongClickListener(MainActivity _mainActivity)
        {
            this._mainActivity = _mainActivity;
        }


        public WhatsOnLongClickListener(TabHost tabHost)
        {

            TabWidget tabWidget = tabHost.TabWidget;
           var tabContent = tabHost.TabContentView;

            FrameLayout _localLayout = (FrameLayout)_mainActivity.FindViewById<FrameLayout>(Resource.Layout.Main);

            tabHost = (TabHost)_localLayout.FindViewById<TabHost>(Resource.Id.TabHost);

       //     tabHost.Visibility = ViewStates.Invisible;
        }


        bool IOnLongClickListener.OnLongClick(View v)
        {


            throw new NotImplementedException();
        }
    }
}



full code is here

https://github.com/h...bile_android_a2

Is This A Good Question/Topic? 0
  • +

Replies To: 'Resource.Id' does not contain a definition for 'TabHost&#

#2 wseng92   User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 631
  • Joined: 23-September 15

Re: 'Resource.Id' does not contain a definition for 'TabHost&#

Posted 12 December 2018 - 06:37 PM

Clean and Rebuild your project.
Was This Post Helpful? 0
  • +
  • -

#3 hexagod   User is offline

  • 😂😂😂
  • member icon

Reputation: 31
  • View blog
  • Posts: 577
  • Joined: 29-October 16

Re: 'Resource.Id' does not contain a definition for 'TabHost&#

Posted 19 December 2018 - 07:26 PM

that doesn't work for this. I'm well aware of the delete resourcedesigner.cs then rebuild and re-add trick. This is an issue where that resource is fundamentally unavailable to any class outside MainActivity (in my estimation having done months of research). Any other resource can be found; it's not an issue of missing int link within resourcedesigner.

I think what I will need to do in order to get this working is create a custom event and then implement a listener inside MainActivity. That is currently above my level of expertise but I'm looking into it.

I know that the TabHost is deprecated but it's also a classic Android UI element and so I'd like to know how to do this just for the fun of it. TabHost has different and decent performance when implemented properly, despite what some say. I've used the brand new UI elements like BottomNavigationView and ViewPager and the performance is not as good as the classic TabHost.

I am retooling this app with the newer UI and methods but I want to keep a version of this classic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1