【发布时间】:2011-07-07 11:35:30
【问题描述】:
我在布局 xml 文件中定义了一个按钮:
<Button
android:id="@+id/my_btn"
android:layout_width="30dip"
android:layout_height="20dip"
android:text="@string/click_me"
android:textSize="10dip"
/>
在我的活动类中,我使用以下代码处理点击事件:
Button myBtn = (Button) findViewById(R.id.my_btn);
myBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showToast();
}
});
public void showToast() {
Context context = getApplicationContext();
CharSequence text = "button clicked";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
我运行我的应用程序,当我按下按钮时,我从 Eclipse LogCat 控制台收到以下错误消息:
我不明白这个错误信息是什么意思?它抱怨什么?我哪里错了?
(请鼠标右击下图,查看图片)
如果您在查看上图时遇到问题,我会在下面写下错误消息:
ActivityThread | enter process activity msg=120
ActivityThread | exit process activity msg=120
WindowManager | waitForLastKey: mFinished=true, mLastWin=null
ViewRoot enter | Dispatching touchevent to com.android.internal.policy.impl.PhoneWindow$DecorView@2fde0c80 touchevent action is 0 X=219.54167 Y=505.3675
...
...
附:更改按钮大小和背景可绘制后出现此错误,听起来很奇怪...我也觉得很奇怪。
-----更新--------
布局文件:
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
...
<TextView
android:id="@+id/upper_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="10sp"
android:textStyle="bold"/>
<Button
android:id="@+id/my_btn"
android:layout_toRightOf="@id/upper_text1"
android:layout_alignTop="@id/upper_text2"
android:layout_width="80dip"
android:layout_height="20dip"
android:background="@drawable/btn_bg"
android:text="@string/click_me"
/>
...
...
【问题讨论】:
-
您可以复制/粘贴日志消息吗?图片太小,无法阅读文字。
-
@Dan,右键单击 -> 查看图像。但我没有看到任何错误
-
只需右键查看即可。它的大小还可以..
-
我认为你走错路了
标签: android android-layout android-emulator android-widget android-manifest