I am trying to get the data from my SQLite table into a List<string> and then into an ArrayAdapter<string> and into a ListView.
How would I get the data pulled from the below code, into a ListView using an ArrayAdapter?
DB Helper.cs:
public List<string> getNoteList()
{
List<string> noteList = new List<string>();
SQLiteDatabase db = this.ReadableDatabase;
ICursor cursor = db.Query(DB_TABLE, new string[] { DB_COLUMN}, null, null, null, null, null);
while (cursor.MoveToNext())
{
int index = cursor.GetColumnIndex(DB_COLUMN);
noteList.Add(cursor.GetString(index));
}
return noteList;
}
As you can see it is put into noteList, but how would I code an array adapter so that the noteList goes into a ListView?
UPDATE 1: MainActivity.cs
public void LoadNoteList()
{
List<string> noteList = dbHelper.getNoteList();
adapter = new ArrayAdapter<string>(this, Resource.Layout.list_black_text, noteList);
lvNotes.Adapter = adapter;
}
Error:
Change noteList's type to ArrayList and add follow line at the place after your ListView being initialization
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, noteList);
listview.setAdapter(adapter);
try this
here cards is my linked-list
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice);
for (MerchantCard card : cards) {
arrayAdapter.add(card.getName());
}
ListView listView = (ListView) mView.findViewById(R.id.listView);
listView.setAdapter(arrayAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedCardTypeId = cards.get(position).getId();
Log.d("request", cards.get(position).getId() + " " + cards.get(position).getName());
}
});
Related
I'm using Live Charts in my application for a pareto chart. I have made a SeriesCollection. I'm loading it from a Stored Procedure in the following way:
public void LoadChart()
{
List<DataTops> dataTops = GetTops();
ChartValues<int> Pareto = new ChartValues<int>();
List<string> timevalues = new List<string>();
int selected = ComboSelect();
IDLables = new List<string>();
foreach (var item in dataTops)
{
values.Add(item.Total);
Pareto.Add(item.Running);
IDLables.Add((item.W) + "." + (item.B));
}
TopAlarms = new SeriesCollection
{
new ColumnSeries
{
Title = "Total",
Values =values,
DataLabels = false,
ScalesYAt = 0,
},
new LineSeries
{
Title = "%",
Values = Pareto,
ScalesYAt = 1,
PointGeometrySize = 0
}
};
public List<DataTops> GetTops()
{
int selected = ComboSelect();
DataSet Ds = new DataSet();
DataSetTableAdapters.TimePerID_TopTableAdapter TimerTopta = new DataSetTableAdapters.TimePerID_TopTableAdapter();
TimerTopta.Fill(Ds.TimePerID_Top, selected);
List<DataTops> Tops = new List<DataTops>();
foreach (DataRow row in Ds.Tables["TimePerID_Top"].Rows)
{
Tops.Add(new DataTops() { Total = (int)row["Total"], W = (int)row["W"], B = (int)row["B"], Amount = (int)row["Amount"], Running = (int)row["Running"] });
}
return Tops;
}
I have a combobox to select an amount to show (selected in the dataset) and a button that I use to update the chart. The Chart works fine, but whenever I press the update button it only adds new data behind the already existing data.
Live charts doesn't automatically clear the chart collection data upon loading so I did this:
private void UpdateChart_Click(object sender, RoutedEventArgs e)
{
if (TopAlarms != null)
{
TopAlarms.Clear();
}
LoadChart();
}
But it still won't clear and reload the chart. How can i reload the chart when the button is pressed so the new selected data amount will show?
after some testing and reasearch I have the following solution for clearing the chart:
try
{
if (TopAlarms != null)
{
TopAlarms.Clear();
}
}
catch { }
This is probably not the best solution but it works for me.
I have been trying to get a List that comes from a WCF and assign its values to a ListView control on Xamarin Android. But, I keep receiving this error,
Cannot implicitly convert type
System.Collections.Generic.List<sometexthere> to
Android.Widget.ListView.
The App code is
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.ACategory);
btnBack = FindViewById<Button>(Resource.Id.btnTest);
txtInform = FindViewById<TextView>(Resource.Id.textView1);
lstSubCat = FindViewById<ListView>(Resource.Id.lstSubCats);
btnBack.Text = "Back";
string mainCat = Intent.GetStringExtra("ButtonClicked") ?? "Item not available";
txtInform.Text = "You are viewing the " + mainCat + " Category. Choises in here will be populated when connected to database";
this.Title = mainCat;
IntSuk.SukMain sukachin = new IntSuk.SukMain();//This is a web reference
sukachin.GetSubCategoryCompleted += Sukachin_GetSubCategoryCompleted;
sukachin.GetSubCategoryAsync(mainCat);
}
private void Sukachin_GetSubCategoryCompleted(object sender, IntSuk.GetSubCategoryCompletedEventArgs e)
{
lstSubCat = e.Result.ToList();//Here is where the error occurs. The result is a List<T> type but lstSubCat is an Android ListView
}
The WCF code that communicates with this is
public List<string> GetSubCategory(string cat)
{
SqlCommand cmd = new SqlCommand("select SubCategoryNameEnglish from SubCategory where Category='"+ cat + "'",Connection);
DataTable dt = new DataTable();
dt = DataManage.ExecuteDT(cmd);//Datamanage is a new class file and no problem with it.
List<string> retList = new List<string>();
int counts = dt.Rows.Count;
int i;
for (i = 0; i <= counts - 1; i++)
{
retList.Add(dt.Rows[i]["SubCategoryNameEnglish"].ToString());
}
return retList; //This is what is returned to the App
}
Is there any way that I can make an explicit conversion or any solution? Any help is appreciated. Thanks!
Thanks for the hint Jason!
Finally it worked in the following way. In the client code,
private void Sukachin_GetSubCategoryCompleted(object sender, IntSuk.GetSubCategoryCompletedEventArgs e)
{
List<string> listItems = new List<string>();
listItems = e.Result.ToList();
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, listItems);
lstSubCat.Adapter = adapter;
}
So I have to make my layout for the first time in C#...
Now I want to be able to tab on a listview item and then go to a detail page with the data of te tapped item.. How can I do this?
I currently have this code;
public MainPage()
{
GeneratePage();
InitializeComponent();
}
private async Task GeneratePage()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
foreach (var f in folders)
{
List<Lists> lists = new List<Lists>();
foreach (int id in f.list_ids)
{
lists.Add(await ApiManager.GetSpecificListAsync(id));
// Debug.WriteLine("ID for list '"+ f.title +"' : " + id);
}
this.Children.Add(new ContentPage
{
Title = f.title,
Content = new ListView
{
ItemsSource = lists
}
});
}
}
Normally I use XAML instead of CodeBehind to create UIs, but the following snippet should do the trick, but I have not tested it.
Just attach to the ItemTapped event. Alternatively you could also add an TapGestureRecognizer onto your ListView.
private async Task GeneratePage()
{
List<Folder> folders = await ApiManager.GetFoldersAsync();
foreach (var f in folders)
{
List<Lists> lists = new List<Lists>();
foreach (int id in f.list_ids)
{
lists.Add(await ApiManager.GetSpecificListAsync(id));
// Debug.WriteLine("ID for list '"+ f.title +"' : " + id);
}
ListView listView = new ListView { ItemsSource = lists };
listView.ItemTapped += ListViewOnItemTapped;
this.Children.Add(new ContentPage
{
Title = f.title,
Content = listView
});
}
}
void ListViewOnItemTapped(object sender, ItemTappedEventArgs itemTappedEventArgs)
{
throw new NotImplementedException();
}
you have a list of ContentPage?? It's very strange. But, normally, for add a tap-event for a ListView item you subscribe to the ItemTapped event.
var list = new ListView();
list.ItemsSource = myItems;
list.ItemTapped += myEventTapped();
Content = list;`
I have created my custom Entry and I need to add some reports to it.
I'm trying to get Reports Dropdown like this
But all my efforts are unsuccessful.
I have action and function like is in the Receipt Entry
public PXAction<MyMasterView> report;
[PXUIField(DisplayName = "Reports", MapEnableRights = PXCacheRights.Select),PXButton(SpecialType = PXSpecialButtonType.Report)]
protected virtual IEnumerable Report(PXAdapter adapter, [PXString(8, InputMask = "CC.CC.CC.CC"), PXStringList(new string[]{"PO649999","PO646000"}, new string[]{"Print My Report","Print Receipt"})] string reportID)
{
List<MyMasterView> list = adapter.Get<MyMasterView>().ToList<MyMasterView>();
if (!string.IsNullOrEmpty(reportID))
{
this.Save.Press();
int num = 0;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
foreach (MyMasterViewcurrent in list)
{
dictionary["PARAMETER"] = current.PARAMETER;
num++;
}
if (num > 0)
{
throw new PXReportRequiredException(dictionary, reportID, string.Format("Report {0}", reportID));
}
}
return list;
}
But as a result I'm getting the following
There are a couple ways you can handle this.
One way is outlined in another question here:
Acumatica - Add additional buttons to Actions drop down to screen CT30100
The other method is to utilize a list and control it with automation steps.
If you look at the PO Receipts screen you can see this.
1) Create your button method that takes a list of other items:
public PXAction<POReceipt> report;
[PXUIField(DisplayName = "Reports", MapEnableRights = PXCacheRights.Select)]
[PXButton]
protected virtual IEnumerable Report(PXAdapter adapter,
[PXString(8, InputMask = "CC.CC.CC.CC")]
[PXStringList(new string[] { "PO646000", "PO632000", "PO622000" }, new string[] { "Purchase Receipt", Messages.ReportPOReceiptBillingDetails, Messages.ReportPOReceipAllocated })]
string reportID)
{
List<POReceipt> list = adapter.Get<POReceipt>().ToList();
if (string.IsNullOrEmpty(reportID) == false)
{
Save.Press();
int i = 0;
Dictionary<string, string> parameters = new Dictionary<string, string>();
foreach (POReceipt doc in list)
{
if (reportID == "PO632000")
{
parameters["FinPeriodID"] = (string)Document.GetValueExt<POReceipt.finPeriodID>(doc);
parameters["ReceiptNbr"] = doc.ReceiptNbr;
}
else
{
parameters["ReceiptType"] = doc.ReceiptType;
parameters["ReceiptNbr"] = doc.ReceiptNbr;
}
i++;
}
if (i > 0)
{
throw new PXReportRequiredException(parameters, reportID, string.Format("Report {0}", reportID));
}
}
return list;
}
Notice the PXStringList that has the possible values and the descriptions.
Then you can control active/inactive state from the Automation Steps.
The step you are missing in your original question is that you still need to add these buttons from the automation steps to add them to the list.
I'm creating a report in VS2013 C# winform application using devExpress XtraReport. I'm trying to use a table in the entity framework as the datasource. I tried this using a binding source, but the data does not show.
From my dataProvider class:
public static List<vwInventoryRequestReport> GetView(int docNo)
{
var items = new List<vwInventoryRequestReport>();
using (var context = new Sage300Entities())
{
var query = from i in context.vwInventoryRequestReports
where i.InventoryRequestHeaderId == docNo
select i;
items = query.ToList();
}
return items;
}
From my main class:
var docNo = Convert.ToInt32(teDocumentNumber.Text);
var items = DataProvider.GetView(docNo);
this.bindingSource2.DataSource = items;
InventoryRequestReport report = new InventoryRequestReport();
report.DataSource = items;
ReportPrintTool tool = new ReportPrintTool(report);