ListView Click Leads to New Page with Definition?

I am a complete beginner in terms of coding for Android and using Xamarin so I have basically been watching tutorials from camposha.com on how to code with these resources. To provide some context essentially I wanted to make an app for my students with all the music terms required for our lessons. I would have a list view with all the terms which students could search for. When they click on the name or item in the list it shows a full definition of the music term.Below is some of the code I have managed for the search function and narrowing down options by starting letters.

`using Android.App;
using Android.Widget;
using Android.OS;
using System.Collections;
using Android.Runtime;
using Android.Content;
using System;
using Android.Views;

namespace MusicTerms
{
[Activity(Label = "musicTerms", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
private SearchView _sv;
private ListView _lv;
private ArrayList _musicterms;
private ArrayAdapter _adapter;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        //INITIALIZE VIEWS
        _lv = FindViewById<ListView>(Resource.Id.listView1);
        _sv = FindViewById<SearchView>(Resource.Id.searchView1);

        //ADD DATA

        addData();

        //ADAPTER

        _adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, _musicterms);
        _lv.Adapter = _adapter;

        _sv.QueryTextChange += _sv_QueryTextChange;
        _lv.ItemClick += _lv_ItemClick;


    }

    private void _lv_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        Toast.MakeText(this,_adapter.GetItem(e.Position).ToString(), ToastLength.Short).Show();
    }

    private void _sv_QueryTextChange(object sender, SearchView.QueryTextChangeEventArgs e)
    {
        //FILTER OR SEARCH
        _adapter.Filter.InvokeFilter(e.NewText);
    }

    private void addData()
    {
        _musicterms = new ArrayList();
        _musicterms.Add("Crescendo");
        _musicterms.Add("Dimmuendo");



    }

}

}

`

I want to somehow store the definitions for each term and for it to launch a new page with the definition of the term displayed in a text view when that particular item is clicked in the list view. At the moment I have no idea on where to begin on adding the definitions or displaying that definition. I have been scouring youtube for tutorials in relation to what I have been doing but I found nothing I can understand.

Answers

  • jaymarvelsjaymarvels GBMember ✭✭

    You need to work out how you want to store this data, whether in a SQLite Db, a WebAPI, Key Value pair in asset etc etc, you will need to decide how you want to store so you can also decide how to access.

    In terms of "A new page" do you mean a new activity, a fragment or custom dialog?

Sign In or Register to comment.