error: 在xml中定义android:onclick=”xxx” [error: String resource ID #0x6]

在组件文件main.xml中,对Button加入:

android:onClick=”onClick_Event

在activity中加入以下代码:

public void onClick_Event(View view) {
TextView textview = (TextView)findViewById(R.id.textView1);
textview.setText(“Button”);
}

只需在正确的Activity 中增加一个成员函数onClick_Event(),并在xml文件中加入对其的使用描述即可。代码结构简单,清晰,代码量也大大减少,并且通过xml文件的可配置性,增长了工程的可维护性,模块化进一步增强! 推崇。

  • android.content.res.Resources$NotFoundException: String resource ID #0x6

想让某个TextView对象显示一个数字,直接调用了setText()方法:tv1.setText(100);  运行时ForceClose

Solution: 

setText(int resid),这里的int型参数表示的是资源ID,而不是显示到TextView的数字。所以要在TextView中显示一个int类型整数,不能直接将此整数直接作为参数。修改为:tv1.setText(String.valueOf(100));

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: