2017-03-25 3 views
0

나는이 튜토리얼을 따라 잘 작동한다. https://developer.xamarin.com/recipes/android/controls/imageview/display_an_imageXamarin - 동적으로 이미지 소스를 변경하는 방법?

하지만 제 경우에는 200 장의 사진이 있습니다. 사용자는 EditText에 단어를 쓰고, 버튼을 클릭 한 후 그림을 각각 보여줍니다. 어떻게 아래 코드에서 영상 소스를 변경할 수 있습니다 edit.Text에 대한

EditText edit = FindViewById<EditText>(Resource.Id.edtName); 

    button.Click += delegate 
     { 
      img.SetImageResource(Resource.Drawable.sample2); 

     }; 

여기서 "sample2를"변화를.

답변

1

는 드로어 블

public void changePhoto() 
    { 
     int MyPhoto; 
     if (edit.Text != string.Empty) 
     { 
      try 
      { 
       MyPhoto = (int)typeof(Resource.Drawable).GetField(edit.Text).GetValue(null); 
      } 
      catch 
      { 
       MyPhoto = Resource.Drawable.ErrorPhoto; 
      } 
      img.SetImageResource(MyPhoto); 
     } 
    } 
    button.Click += delegate 
    { 
     changePhoto(); 
    }; 
을 변경하는 방법을 사용합니다 (텍스트는 ... 사용자에 대해 쓰기)