I may be dense here, but here is my problem. I am writing an android app that is supposed to manage an inventory of items. There are multiple Spinner and AutoCompleteTextView objects on one of my layouts that I am trying to populate from one function, instead of having one function for each.
Here is what I have... The object _type is supposed to become a reference to the class for the Sqlite query to populate data in. I used Object in this sample code, but I have run it, as var, object, type... I have several issues coming up here, 1) I get '_table' is a variable but is used like a type 2) I am getting a similar problem with _res when I start trying to parse the data returned from the db connection
In essence what I want to do is use a variable as a place holder for a type. I've tried using a number of casts, and functions like .GetType(), but they still throw the same "x is a variable but used like a type". When I use it in the context of the list that receives the data I get the message "list requires one type argument"
At the moment I have this working by just having independent functions for each form item I am working with, but that's chunky, and I'd love to extend this to work on all form items that get data from the DB.
public ArrayAdapter<string> PopulateAdapter(Context _c,
MyDatabase.enTables _which,
MyDatabase.Options _o =null)
{
string[] _l;
SQLiteConnection db = new SQLiteConnection(MyDatabase.GetDBFilePath());
string _sql;
Object _table;
List<_table> _res;
switch (_which)
{
case GMDatabase.enTables.Manufacturers:
_sql = "SELECT * FROM Manufacturers";
_table = MyDatabase.Manufacturer;
break;
case GMDatabase.enTables.Styles:
_sql = "SELECT * FROM Styles";
_table = MyDatabase.Styles;
break;
}
_res<_table> = new List<_table>;
_res = db.Query<_table>(_sql);
if (_res.Count)
{
for (int i = 0; i < size; i++)
{
_l[i + 1] = _res[i].Name;
}
return new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, _l);
}
return null;
}
Thank you for taking a look, and any advice or ideas would be most appreciated!