Question I want to make my listview object to be expandable?

Aproko234

New member
Joined
Apr 25, 2022
Messages
3
Programming Experience
Beginner
I am developing a xamarin.forms app that would be available for android & ios phones.

I urgently need to add listview grouping ability to my menu.

I would like the Record Abuse Item, for example to have Record Audio, Take a Picture, Take a Video, Livestream , etc as Children that would appear underneath it when a user taps on it.

I basically need someone to look at my code and insert the relevant portions that would allow me to achieve my objective.

This is where the Item is defined as a Class:
C#:
    public class Item
    {
        public string Id { get; set; }
        public string Text { get; set; }
        public string Description { get; set; }
    }
I have defined a sub_item class and I don't know what to do next to link the sub_items with the Items:
C#:
    public class Sub_Item
    {
        public string Id { get; set; }
        public string Text { get; set; }
        public string Description { get; set; }

        public Item Item { get; set; }
    }
This is where the Item class is collecting its data from:
C#:
    public class MockDataStore : IDataStore<Item>
    {
        readonly List<Item> items;

        public MockDataStore()
        {
            items = new List<Item>()
            {
                new Item { Id = Guid.NewGuid().ToString(), Text = "Report Abuse" Description="Initiate (audiovisual) recording for unfolding event around you, which can either be transmitted simultaneously or stored on your phone for later transmission." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "RED Zone", Description="View or manage (if your are the Admin) dangerous areas that have been automatically identified by the app or manually captured (by the Admin)." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "Location Inquiry", Description="Make use of GPS to determine your current location." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "Notify", Description="Notify specific people of your present situation." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "Voice2Text", Description="Voice to text translator." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "Support & Counselling", Description="You can either browse through our recommended tips of what to do before or after an abuse has occured or Chat with a representative for support and counselling." },
                new Item { Id = Guid.NewGuid().ToString(), Text = "Options", Description="Setup and configure several settings for the app." }
            };
        }

        public async Task<bool> AddItemAsync(Item item)
        {
            items.Add(item);

            return await Task.FromResult(true);
        }

        public async Task<bool> UpdateItemAsync(Item item)
        {
            var oldItem = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
            items.Remove(oldItem);
            items.Add(item);

            return await Task.FromResult(true);
        }

        public async Task<bool> DeleteItemAsync(string id)
        {
            var oldItem = items.Where((Item arg) => arg.Id == id).FirstOrDefault();
            items.Remove(oldItem);

            return await Task.FromResult(true);
        }

        public async Task<Item> GetItemAsync(string id)
        {
            return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
        }

        public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
        {
            return await Task.FromResult(items);
        }
    }
}
I am expecting a quick response to help in resolving this issue.

Thanks.
 

Attachments

  • Screen 1.png
    Screen 1.png
    12.5 KB · Views: 11
  • Screen 2.png
    Screen 2.png
    30.6 KB · Views: 11
Last edited by a moderator:
From what I can see from your screenshots, it doesn't look like those "child" items are being presented within the same list view. It looks like a new list view is shown.
 
From what I can see from your screenshots, it doesn't look like those "child" items are being presented within the same list view. It looks like a new list view is shown.
You are correct. I don't know how I am going to include for example ("Record Audio", "Take a Picture", Take a Video", "Livestream") and make them appear under Report Abuse in the Services view. I want to know how I could do this programmatically without crashing the app. Thanks.
 
Last edited:
How are you currently bringing up a menu? Wouldn't you just do the same thing?
 
How are you currently bringing up a menu? Wouldn't you just do the same thing?
It is not as easy as you make it seem since I am just trying to get to grips with mobile apps development and of course being new to xamarin.forms. I am sending you the app source code (zipped), so you can see yourself how the menu is being called. You would need Visual Studio 2022 with xamarin.forms installed to be able to access the code once you unzip them to a folder. Thanks.
 

Attachments

  • SV Reporting.Android.zip
    743.8 KB · Views: 6
Back
Top Bottom