<Application>.Android.Resource.Layout does not contain a definition for SimpleListItem2

I'm trying to implement a ListView in my Android application and it seems like all examples are calling on one of these default ListViews.

At first I thought I'd have to implement SimpleListView2 myself as a layout, but after looking at a number of codebases on Github, it appears like all I should have to do is _activity.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem2, null), but I'm not having any success. All of the SimpleLists, etc... are not available in my project. Am I missing an assembly?

For reference, here is my SimpleListItem2Adapter:

using Android.App;
using Android.Views;
using Android.Widget;
using BarcodeScanner.Entities.Scans;
using System;
using System.Collections.Generic;
using System.Linq;

namespace BarcodeScanner.Android.Resources.activities.Sponsors
{
    public class SimpleListItem2Adapter : BaseAdapter<SponsorBadgeScans>
    {
        private readonly List<SponsorBadgeScans> _recentScans;
        private readonly Activity _activity;

        public SimpleListItem2Adapter(Activity activity, IEnumerable<SponsorBadgeScans> recentScans)
        {
            _recentScans = recentScans.ToList();
            _activity = activity;
        }

        public override long GetItemId(int position)
        {
            return position;
        }

        public override SponsorBadgeScans this[int index]
        {
            get { return _recentScans[index]; }
        }

        public override int Count
        {
            get { return _recentScans.Count; }
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;

            if (view == null)
            {
                view = _activity.LayoutInflater.Inflate(Android.Resource.Layout.SimpleListItem2, null); // [...] does not contain a definition for SimpleListItem2
            }

            var scan = _recentScans[position];

            TextView text1 = view.FindViewById<TextView>(Android.Resource.Id.Text1); // [...] does not contain a definition for Text1
            text1.Text = String.Format("{0} {1}", scan.FirstName, scan.LastName);

            TextView text2 = view.FindViewById<TextView>(Android.Resource.Id.Text2); // [...] does not contain a definition for Text2
            text2.Text = String.Format("{0}", scan.CompanyName);

            return view;
        }
    }
}

And here is my ListActivity:

using Android.App;
using Android.OS;
using Android.Widget;
using BarcodeScanner.Android.Common;
using BarcodeScanner.Android.Resources.activities.Sponsors;

namespace BarcodeScanner.Android.Resources.activities
{
    [Activity(Label = "ViewRecentLeadsActivity")]
    public class ViewRecentLeadsActivity : ListActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            using (var scanManager = new ScanManager())
            {
                var recentScans = scanManager.GetRecentScans("blah");

                if (recentScans != null)
                {
                    var adapter = new SimpleListItem2Adapter(this, recentScans);
                    this.ListAdapter = adapter;
                }
            }
        }

        protected override void OnListItemClick(ListView l, global::Android.Views.View v, int position, long id)
        {
            base.OnListItemClick(l, v, position, id);
        }
    }
}

Posts

  • ThomasCharlesThomasCharles USMember ✭✭

    So, because I named my project BarcodeScanner.Android, Android.Resource.Layout.SimpleListItem2 was actually looking for BarcodeScanner.Android.Resource.Layout.SimpleListItem2 due namespace issues. I moved the SimpleListItem2Adapter to a different namespace and all was good.

  • CheesebaronCheesebaron DKInsider, University mod

    You are right. When having Android in your namespace you will encounter stuff like this. So you will need to either change the namespace or afaik, you can use global::Android.Resource.Layout.SimpleListItem2 instead.

  • iamaurousiamaurous PHMember ✭✭

    Need some help here too, got the same error. But this time, not 'cause of the namespace. Here's my code:

    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.Widget;
    
    namespace MyDreamVATrial
    {
        class DialogSignUp : DialogFragment
        {
            public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
            {
                base.OnCreateView(inflater, container, savedInstanceState);
    
                var view = inflater.Inflate(Resource.Layout.SignUp, container, false);  //this is the error
    
                return view;
            }
        }
    }
    

    And this is what my Signup.axml contains:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#67C9FA"
        android:weightSum="100"
        android:minHeight="25px"
        android:minWidth="25px">
        <EditText
            android:id="@+id/FirstName"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="20dp"
            android:hint="First Name"
            android:textColor="#929497"
            android:background="#FFFFFF" />
       <EditText
            android:id="@+id/Email"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="20dp"
            android:hint="Email Address"
            android:textColor="#929497"
            android:background="#FFFFFF"
            android:inputType="textEmailAddress" />
        <EditText
            android:id="@+id/Password"
            android:layout_width="match_parent"
            android:layout_height="35dp"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="10dp"
            android:paddingLeft="20dp"
            android:hint="Password"
            android:textColor="#929497"
            android:background="#FFFFFF"
            android:inputType="textPassword" />
        <Button
            android:text="Sign Up"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:id="@+id/bntSignUp"
            android:layout_gravity="center"
            android:layout_weight="15"
            android:layout_marginTop="25dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="10dp"
            android:textSize="20dp"
            android:textStyle="normal"
            android:background="#929497" />
    </LinearLayout>
    

    Thank you

  • PieterjanDeClippelPieterjanDeClippel USMember ✭✭

    Indeed if you name your project Android, that's a problem.
    I always name my project Droid to avoid this.
    Else you can find views using the global identifier

    global::Android.Resource.Layout.SimpleListItem2

Sign In or Register to comment.