예제 #1
0
        public static ShowFragment newInstance(string answer)
        {
            ShowFragment fragment = new ShowFragment();

            fragment.answer = answer;
            return(fragment);
        }
예제 #2
0
        public void OnClick(View v)
        {
            //string folder = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
            var    dataPath = System.Environment.SpecialFolder.ApplicationData;
            string path     = Path.Combine(System.Environment.GetFolderPath(dataPath).Split("files")[0] + @"files", FileName);

            //File.Create(path + "newFile.png");
            //File.Delete(path);
            if (!File.Exists(path))
            {
                File.Create(path);
            }

            switch (v.Id)
            {
            case Resource.Id.btn_view:
                StringBuilder stringBuilder = new StringBuilder();

                List <string> storage = File.ReadAllLines(path).ToList();
                foreach (var item in storage)
                {
                    string[] temp = item.Split(';');
                    stringBuilder.Append($"{temp[0]} ({temp[1]})\n");
                }

                ShowFragment        showFragment = ShowFragment.newInstance(stringBuilder.ToString());
                FragmentTransaction transaction  = this.FragmentManager.BeginTransaction();
                transaction.Replace(Resource.Id.container, showFragment);
                etQuestion.Text = "";
                transaction.AddToBackStack(null);
                transaction.Commit();
                break;

            case Resource.Id.btn_continue:

                int         selectedId  = radioGroup.CheckedRadioButtonId;
                RadioButton radioButton = radioGroup.FindViewById <RadioButton>(selectedId);
                string      answer      = radioButton.Text;
                string      question    = etQuestion.Text.ToString();
                File.AppendAllText(path, $"{question};{answer};\n");
                etQuestion.Text = "";
                //etQuestion.ClearFocus();
                Toast.MakeText(v.Context, "Message saved successfully!", ToastLength.Long).Show();
                break;
            }
        }