这是我在Xamarin for Android中的第一个应用程序。我想与两个屏幕开始:ListView用于在Xamarin中下载文件
- 第一(主)屏幕具有3个按钮:负载任务号1,负载任务号2,显示任务列表,
- 推动第一或第二按钮后,该项目是在第二个屏幕添加到列表中,
- 按下第三个按钮后,打开第二个屏幕与任务列表。
但我有ListView的问题。例如:我希望将第一个任务添加到ListView,回到第一个屏幕,添加第二个任务(第一个任务应该已经在列表中),回到第一个屏幕,按下按钮显示第二个屏幕,两个任务应该已经在那里。
主要活动:
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button addButton1 = FindViewById<Button>(Resource.Id.AddButton1);
Button addButton2 = FindViewById<Button>(Resource.Id.AddButton2);
Button downloadsScreen = FindViewById<Button>(Resource.Id.DownloadsScreen);
var intent = new Intent(this, typeof(Downloads));
addButton1.Click += (object sender, EventArgs e) =>
{
intent.PutExtra("downloads", "wartosc1");
StartActivity(intent);
};
addButton2.Click += (object sender, EventArgs e) =>
{
intent.PutExtra("downloads", "wartosc2");
StartActivity(intent);
};
downloadsScreen.Click += (object sender, EventArgs e) =>
{
StartActivity(intent);
};
}
}
活动与任务:
public class Downloads : ListActivity
{
Dictionary<string, Task> zadania = new Dictionary<string, Task>();
List<string> listaZadan = new List<string>();
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
ArrayAdapter<string> lista = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, listaZadan);
}
protected override void OnStart()
{
var download = Intent.GetStringExtra("downloads") ?? null;
Task zadanie = new Task();
EncryptAndDecrypt decryption = new EncryptAndDecrypt();
zadanie = JsonConvert.DeserializeObject<Task>(decryption.Decrypt(download, "haslo"));
if (!zadania.ContainsKey(zadanie.Name))
{
zadania.Add(zadanie.Name, zadanie);
listaZadan.Add(zadanie.Name);
}
else
new AlertDialog.Builder(this).SetMessage("Zadanie zostało już dodane do pobierania").Show();
}
}
我怎样才能解决呢?这样的列表是显示下载文件的好方法吗?将来我希望将ProgressBar添加到ListView中的每个项目。请不要发送链接到教程,我看到了他们。我关心处理它的人的信息。