這是我在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中的每個項目。請不要發送鏈接到教程,我看到了他們。我關心處理它的人的信息。