Retrieve tables from list in Xamarin.Android

KLubin 1 Reputation point
2020-11-19T02:17:51.497+00:00

Hi,
I’m working on an SQLite database GUI using SQLiteOpenHelper, and I’m trying to have it so that the user can access the list of tables that they have created. I have already figured out how to show the tables that were and are created in a list, but I still need to find away so that the selected list item points to and refers to its corresponding table. Right now, I have it so that it will return the lastly created table and its info, but I instead need it to return the table info from whichever table was just pressed. Any ideas or suggestions on how to go about this? Please don’t hesitate to let me know if you need further information or code.
Thanks!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,337 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,681 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2020-11-19T04:13:53.977+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    I have it so that it will return the lastly created table and its info, but I instead need it to return the table info from whichever table was just pressed

    @KLubin For this function, try detecting the ItemClick event of the listView to get the current position. Then get the item data using the position to retrive info from the table. I write a basic demo about the function, you could refer to the code:

       ListView listview_ = FindViewById<ListView>(Resource.Id._listview);  
         
       List<CustomModel> dataList = new List<CustomModel>();  
       //get data from the database  
         
       CustomAdapter adapter = new CustomAdapter(dataList);  
       listview_.SetAdapter(adapter);  
         
       listview_.ItemClick += (o, s) =>  
       {  
           string name = list[s.Position].Name;  
           //query the data from the table with the name  
       };  
    

    CustomAdapter class

       public class CustomAdapter : BaseAdapter<CustomModel>  
       {  
           List<CustomModel> list_ = new List<CustomModel>();  
           public _Adapter(List<CustomModel> list_)  
           {  
               this.list_ = list_;  
           }  
           ...  
           public override View GetView(int position, View convertView, ViewGroup parent)  
           {  
               var view = convertView;  
               view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.layout1, parent, false);  
               var textview = view.FindViewById<TextView>(Resource.Id.text_);  
               textview.Text = list_[position].Name;  
         
               return view;  
           }  
       }  
    

    CustomModel class

       public class CustomModel  
       {  
           ...  
           public string Name { get; set; }  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.