我在收音机组中有两个单选按钮。单击每个单选按钮后,我想使用可从sql server中找到的数据库中不同的值填充可搜索的微调器。我编写了以下代码:
public class Invoice_hist_frg : Fragment
{
List<invoice_details> tableItem_invoice = new List<invoice_details>();
RadioButton rdbtn_per_acc, rdbtn_per_item;
SearchableSpinner searchableSpinner;
private List<KeyValuePair<string, string>> spinner_per_acc=new List<KeyValuePair<string, string>>();
private List<KeyValuePair<string, string>> spinner_per_item= new List<KeyValuePair<string, string>>();
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your fragment here
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Use this to return your custom view for this Fragment
View view = inflater.Inflate(Resource.Layout.invoice_history, container, false);
WSitems.WebService1 ws = new WSitems.WebService1();
ws.Invoice_historyAsync();
ws.Invoice_historyCompleted += Ws_Invoice_historyCompleted;
rdbtn_per_acc = view.FindViewById<RadioButton>(Resource.Id.radioButton1);
rdbtn_per_item= view.FindViewById<RadioButton>(Resource.Id.radioButton2);
searchableSpinner =view.FindViewById<SearchableSpinner>(Resource.Id.searchablespinner);
rdbtn_per_acc.Click += Rdbtn_per_acc_Click;
rdbtn_per_item.Click += Rdbtn_per_item_Click;
return view;
}
private void Ws_Invoice_historyCompleted(object sender, WSitems.Invoice_historyCompletedEventArgs e)
{
string[] InvNbr;
string[] InvDate;
string[] Account;
string[] accName;
string[] Cur;
string[] InvType;
string[] item;
string[] itemname;
string[] Unit;
string[] Quantity;
string[] Price;
string[] Vat;
string[] Total;
try
{
InvNbr = e.Result.InvNbr;
InvDate = e.Result.InvDate;
Account = e.Result.Account;
accName = e.Result.accName;
Cur = e.Result.Cur;
InvType = e.Result.InvType;
item = e.Result.item;
itemname = e.Result.itemname;
Unit = e.Result.Unit;
Quantity = e.Result.Quantity;
Price = e.Result.Price;
Vat = e.Result.Vat;
Total = e.Result.Total;
//spinner_per_acc = new List<KeyValuePair<string, string>>();
//spinner_per_item = new List<KeyValuePair<string, string>>();
//tableItems.Add(new itemproperties() { itembarcode = "Code", name = "Description", itemsunitcode = "unit", currentQuantity = "Quantity", CostPrice="CostPrice", moreInfo = "Info" });
for (int i = 0; i < Account.Length; i++)
{
tableItem_invoice.Add(new invoice_details() { InvNbr = InvNbr[i], InvDate = InvDate[i], Account = Account[i], accName = accName[i],
Cur = Cur[i],
InvType = InvType[i],
item = item[i],
itemname = itemname[i],
Unit = Unit[i],
Quantity = Quantity[i],
Price = Price[i],
Vat = Vat[i],
Total = Total[i],
});
spinner_per_acc.Add(new KeyValuePair<string, string >(accName[i] + '-' + Cur[i], Account[i] + '-' + Cur[i]));
spinner_per_item.Add(new KeyValuePair<string, string>(itemname[i] + '-' + Cur[i], item[i] + '-' + Cur[i]));
}
}
catch (System.Reflection.TargetInvocationException exp)
{
}
}
private void Rdbtn_per_item_Click(object sender, EventArgs e)
{
List<string> spinner_item = new List<string>();
foreach (var item in spinner_per_item)
spinner_item.Add(item.Key);
//spinner_item.Add("ljhg");
//spinner_item.Add("ljhg");
//spinner_item.Add("ljhg");
searchableSpinner.Adapter = new ArrayAdapter<String>(this.Context, Resource.Layout.support_simple_spinner_dropdown_item, spinner_item);
}
private void Rdbtn_per_acc_Click(object sender, EventArgs e)
{
List<string> spinner_acc = new List<string>();
foreach (var item in spinner_per_acc)
spinner_acc.Add(item.Key);
//spinner_acc.Add("ytrew");
//spinner_acc.Add("ytrew");
//spinner_acc.Add("ytrew");
searchableSpinner.Adapter=new ArrayAdapter<String>(this.Context, Resource.Layout.support_simple_spinner_dropdown_item, spinner_acc);
}
}
}
我的问题是我首先选择的单选按钮没有使微调框充满任何东西。但是,当我单击第二个并返回到第一个时,微调框将充满所需的数据。我尝试用我添加的数据而不是数据库中的数据填充它,但是效果很好,但是为什么它不能与数据库提供的数据一起使用呢? 预先感谢