오늘 앱을 프로그래밍하는 동안 갑자기 이상한 동작이 발생했습니다. 내 애플 리케이션을위한 백 스페이스 버튼을 만들고 있었지만 컴파일러는 단지 코드 조각을 건너 뛰고 있었다. 내 main.axml의 레이아웃은 다음과 같습니다.이상하게도 Xamarin Visual Studio의 코드 조각을 건너 뛰는 프로그램 2017
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<EditText
android:text="123456123456123456"
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center|left"
android:background="#ffffff"
android:textSize="20sp"
android:textColor="#000000" />
<TextView
android:text="Text"
android:id="@+id/result"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center|left"
android:background="#555555"
android:textSize="20sp"
android:textColor="#ffffff" />
<Button
android:text="Backspace"
android:id="@+id/bksp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#555555"
android:textSize="20sp"
android:textColor="#ffffff" />
</LinearLayout>
그리고 여기에 내가 배치 및 안드로이드 (6) 장치에이 코드를 실행하면 내 MainActivity.cs 내용
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Views;
using System.Timers;
namespace App2
{
[Activity(Label = "App2", MainLauncher = true, WindowSoftInputMode = SoftInput.StateAlwaysHidden)]
public class MainActivity : Activity
{
private bool Bksp_isdown = false;
private int intt = 0;
private Timer Bksp_tmr;
private Button Bksp;
private EditText Inputt;
private TextView Resultt;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
this.Bksp_tmr = new Timer(500);
this.Bksp = this.FindViewById<Button>(Resource.Id.bksp);
this.Inputt = this.FindViewById<EditText>(Resource.Id.input);
this.Resultt = this.FindViewById<TextView>(Resource.Id.result);
this.Inputt.ShowSoftInputOnFocus = false;
this.Bksp.Touch += this.B_backspace_Touch;
this.Bksp_tmr.Elapsed += this.Bksp_tmr_Elapsed;
}
private void Bksp_tmr_Elapsed(object sender, ElapsedEventArgs e)
{
this.Resultt.Text = "worked"
+ this.Bksp_isdown.ToString() + this.Inputt.SelectionStart.ToString();
while (true)
{
this.intt = this.intt + 100;
this.Backspace();
}
}
private void B_backspace_Touch(object sender, View.TouchEventArgs e)
{
this.Bksp_isdown = true;
if (e.Event.Action == MotionEventActions.Down)
{
this.Backspace();
this.Bksp_tmr.Start();
}
else if (e.Event.Action == MotionEventActions.Up)
{
this.Bksp_tmr.Stop();
this.Bksp_isdown = false;
}
}
private bool Backspace()
{
intt++;
this.Bksp.Text = intt.ToString();
if (this.Inputt.SelectionStart == 0)
return false;
string str = this.Inputt.Text;
int sel = this.Inputt.SelectionStart;
str = str.Substring(0, sel - 1) + str.Substring(sel);
this.Inputt.Text = str;
this.Inputt.SetSelection(sel - 1);
return true;
}
}
}
, 난 이상한 행동을 보았다. 위의 Bksp_tmr_Elapsed라는 메서드가 있는데, 프로그램에서 부분적으로 while (true)과 그 안의 코드가 완전히 무시되었다. 나는 내 인생에서 그런 행동을 보지 못했습니다. while 루프에서 상수 부울 표현식을 사용하는 이유를 묻습니다. 이것은 응용 프로그램이 다운 될 때까지 무한 루프가 발생할 수 있으므로 코드가 정상적으로 실행되지 않았기 때문입니다.하지만 불행히도 아닙니다. 도와주세요!!
업데이트 : 코드를 검사하여 Bksp_tmr_Elapsed 메소드의 첫 번째 행만 앱에서 실행되었다는 점에 유의해야합니다. 스크린 샷을 제공하는 코드를 약간 변경했습니다.
Check here the first two lines in the method Bksp_tmr_Elapsed.
이제 우리는 분명히 장치에서 앱이 하나를 업데이트하고 단순히 방법의 다른 모든 라인을 무시하는 결론을 만들 수 있습니다. 컴파일러가 내가 모르는 메서드의 두 번째 줄에 추가하는 숨겨진 return 문과 같거나 모름니다. 이걸 설명해주세요 !!!
답변을 주셔서 감사 합니다만, 아니요, 문제는 잘못된 배포가 아니 었습니다. 나는 그 질문을 갱신했다. –
악의적 인 일이 있습니다. 나는이 병이 재발 할 수 있는지 잠시 후에 생각해 봅니다. –
나는이 문제를 내가 더 빨리 생각하지 못했다고 생각합니다. 코드에 catch를 추가하고이 오류를 발견했습니다. {Android. Util.AndroidRuntimeException : 뷰 계층 구조를 만든 원래 스레드 만 해당 뷰를 만질 수 있습니다. –