Android SDK Tools Rev.17 - onClick - 找不到对应的方法处理程序 [英] Android SDK Tools Rev.17 - onClick - Corresponding method handler not found
问题描述
我将 Android SDK 工具更新至修订版 17,打开 Eclipse 后,我在问题"视图中发现了更新前不存在的新错误列表.这些错误出现在我为按钮定义了 onClick 属性的 XML 布局文件中.将鼠标悬停在错误消息示例上:
I updated Android SDK Tools to revision 17 and after I opened Eclipse I found a list of new errors in the 'Problems' view which weren't there before the update. These errors were in XML Layout files where I had defined the onClick attribute for buttons. On mouse-over the error message example:
未找到对应的方法处理程序'public void @string/timespanDefinition_btnSave_Click(android.view.View)'"
"Corresponding method handler 'public void @string/timespanDefinition_btnSave_Click(android.view.View)' not found"
返回.我已经为这个事件名称定义了相应的方法处理程序和字符串表示.这个问题的原因和解决方法是什么?
returned. I have already defined the corresponding method handler and the string representation for this event name. What is the cause and solution of this problem?
一些代码:
XML 布局
<ToggleButton
android:id="@+id/timespanDefinition_tglVibration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="@string/timespanDefinition_tglVibration_Click"
android:saveEnabled="true" />
扩展 XML 布局的活动
Activity which inflates XML Layout
public class TimespanDefinitionActivity extends Activity
{
// -- Attributes -- //
private long mRowId = -1;
private StringBuilder mBitWeekDays;
private String mTitle;
private EditText txtTitle;
private TabHost tabHost;
private TimePicker tmepkrStart;
private TimePicker tmepkrEnd;
private CheckBox[] weekDays;
private SeekBar skbrVolume;
private ToggleButton tglVibration;
// -- Class Events -- //
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.timespan_definition);
initializeResources();
Bundle extras = getIntent().getExtras();
// Get the time-span Row ID
mRowId = (extras != null) ? extras.getLong(RVSUtilities.getDefaultPackage() + TimespanScheduleTable.KEY_ROWID)
: -1;
populateResources();
}
// -- User Events -- //
public void tglVibration_Click(View v)
{
if (((ToggleButton) v).isChecked())
{
Vibrator vibrate = (Vibrator) getSystemService(VIBRATOR_SERVICE);
vibrate.vibrate(1000);
}
}
strings.xml:
strings.xml:
<string name="timespanDefinition_tglVibration_Click">tglVibration_Click</string>
注意:该应用针对的是 Android 2.3.3,特别是 Google API 版本 10
Note: The app is targeting Android 2.3.3 specifically Google API version 10
谢谢.
推荐答案
这个问题的原因和解决方法是什么?
What is the cause and solution of this problem?
原因是您使用字符串资源作为方法名称.
The cause is your use of a string resource for the method name.
解决方法是去掉字符串资源,直接把方法名放在android:onClick
属性中.
The solution is to get rid of the string resource and to put the method name in the android:onClick
attribute directly.
更新:如果标记没有消失,请右键单击项目,然后选择 Android 工具 > 清除 Lint 标记.
UPDATE: If the markers do not go away, right-click over the project, and choose Android Tools > Clear Lint Markers.
这篇关于Android SDK Tools Rev.17 - onClick - 找不到对应的方法处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!