Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getText被不间断地调用_Android_Android Edittext - Fatal编程技术网

Android getText被不间断地调用

Android getText被不间断地调用,android,android-edittext,Android,Android Edittext,我有一个类,我已经定义为EditText的扩展/ 我用它来解决我们一直遇到的问题,但没有出现正确合理的提示。 因此,我编写了自己的代码,在内部实现提示 除此之外,我重写了getText方法,以便在值等于提示的情况下返回null。问题是getText被称为不间断。它不是递归调用的。我在那里放了一个计数器,它肯定是在执行下一个呼叫之前退出一个呼叫 @Override public Editable getText(){ depth++; calls++; Log.d(

我有一个类,我已经定义为EditText的扩展/ 我用它来解决我们一直遇到的问题,但没有出现正确合理的提示。 因此,我编写了自己的代码,在内部实现提示

除此之外,我重写了getText方法,以便在值等于提示的情况下返回null。问题是getText被称为不间断。它不是递归调用的。我在那里放了一个计数器,它肯定是在执行下一个呼叫之前退出一个呼叫

    @Override
public Editable getText(){
    depth++;
    calls++;
    Log.d("RightJustifiedEditText","getText  - start. Depth =  " + depth + "   calls = " + calls);
    Editable result = (isEmpty?Editable.Factory.getInstance().newEditable(hint):super.getText());
    depth--;
    Log.d("RightJustifiedEditText","getText  - return: " + result + "    Depth = " + depth);
    return result;
}
当我运行此命令时,每次深度值显示为1,然后显示为0。 电话的价值一直在上升

如果我删除super.getText并在它的位置放置一个常量,那么它看起来是正常的

从调试跟踪中可以看到,它是从布局中调用的:

RightJustifiedEditText.getText() line: 115  
RightJustifiedEditText(EditText).getText() line: 48 
RightJustifiedEditText(TextView).getSelectionStart() line: 5892 
RightJustifiedEditText(TextView).onDraw(Canvas) line: 4057  
RightJustifiedEditText(View).draw(Canvas) line: 6880    
RelativeLayout(ViewGroup).drawChild(Canvas, View, long) line: 1646  
RelativeLayout(ViewGroup).dispatchDraw(Canvas) line: 1373   
TextFieldElement(ViewGroup).drawChild(Canvas, View, long) line: 1644    
TextFieldElement(ViewGroup).dispatchDraw(Canvas) line: 1373 
LinearLayout(ViewGroup).drawChild(Canvas, View, long) line: 1644    
LinearLayout(ViewGroup).dispatchDraw(Canvas) line: 1373 
DoctorSearchElement(ViewGroup).drawChild(Canvas, View, long) line: 1644 
DoctorSearchElement(ViewGroup).dispatchDraw(Canvas) line: 1373  
LinearLayout(ViewGroup).drawChild(Canvas, View, long) line: 1644    
LinearLayout(ViewGroup).dispatchDraw(Canvas) line: 1373 
ScrollView(ViewGroup).drawChild(Canvas, View, long) line: 1644  
ScrollView(ViewGroup).dispatchDraw(Canvas) line: 1373   
ScrollView(View).draw(Canvas) line: 6986    
ScrollView(FrameLayout).draw(Canvas) line: 357  
ScrollView.draw(Canvas) line: 1409  
RelativeLayout(ViewGroup).drawChild(Canvas, View, long) line: 1646  
RelativeLayout(ViewGroup).dispatchDraw(Canvas) line: 1373   
RelativeLayout(View).draw(Canvas) line: 6883    
FrameLayout(ViewGroup).drawChild(Canvas, View, long) line: 1646 
FrameLayout(ViewGroup).dispatchDraw(Canvas) line: 1373  
FrameLayout(View).draw(Canvas) line: 6883   
FrameLayout.draw(Canvas) line: 357  
LinearLayout(ViewGroup).drawChild(Canvas, View, long) line: 1646    
LinearLayout(ViewGroup).dispatchDraw(Canvas) line: 1373 
PhoneWindow$DecorView(ViewGroup).drawChild(Canvas, View, long) line: 1644   
PhoneWindow$DecorView(ViewGroup).dispatchDraw(Canvas) line: 1373    
PhoneWindow$DecorView(View).draw(Canvas) line: 6883 
PhoneWindow$DecorView(FrameLayout).draw(Canvas) line: 357   
PhoneWindow$DecorView.draw(Canvas) line: 1862   
ViewRoot.draw(boolean) line: 1522   
ViewRoot.performTraversals() line: 1258 
ViewRoot.handleMessage(Message) line: 1859  
ViewRoot(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 3683    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 839  
ZygoteInit.main(String[]) line: 597 
NativeStart.main(String[]) line: not available [native method]  
这是直接包含它的布局:

<?xml version="1.0" encoding="UTF-8"?>

我在这里猜,但是你确定super.getText没有使它成为递归调用吗?似乎不是,因为深度没有变大。在0和1之间上下移动。另外,在我重新开始之前,我会让消息开始并按顺序返回。调用getText的代码在哪里?也许有更好的方法解决您的问题。它直接来自布局。请参阅更新。好的,我不支持Android,但我会尝试提出比你现在做的更好的建议。该方法是否需要可重写?能否删除“@overridable”指令,看看这是否解决了问题?
<com.applicat.meuchedet.views.RightJustifiedEditText
    android:id="@+id/text_field_element_text_field"
    android:layout_width="170dip"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:textColor="@color/text_field_color"
    android:textSize="14sp"
    android:layout_marginRight="5dip"
    android:paddingLeft="15dip"
    android:paddingRight="15dip"
    android:gravity="right|center_vertical"
    android:inputType="text"
    android:lines="1"
    android:scrollHorizontally="true"
    android:ellipsize="end"
    android:background="@drawable/text_field_bg"
    />
<TextView
    android:id="@+id/text_field_element_prompt"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentRight="true"
    android:gravity="center_vertical|right"
    android:layout_centerVertical="true"
    android:textSize="16sp"
    android:singleLine="true"
    />