初学android ,请教2

zzxap 2011-02-24 11:31:34


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/b01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

中的id 为什么要这样写。android:id="@+id/b01" b01才是id?
怎样为该button加一个点击事件
...全文
154 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
feifei694893239 2011-03-03
  • 打赏
  • 举报
回复
学习了,原来+id是引用已有的的id,直接id是引用已经存在的id
敬事 2011-03-03
  • 打赏
  • 举报
回复
大家说得很好,没啥帮的了。。。哈
儿大不由爷 2011-02-24
  • 打赏
  • 举报
回复
表示是新增的ID吧
将Button对象与界面中的关联上findVIewByID
然后用这个对象这是一个点击事件的Listener,这个Listerner就能监听到点击事件了
筱周 2011-02-24
  • 打赏
  • 举报
回复
这个是标签规范吧
为该button加一个点击事件
Button button;
button = (Button)findViewById(R.id.b01);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//点击事件
}
});
icoo000 2011-02-24
  • 打赏
  • 举报
回复
@+id是指增加一个id的意思,@id是指引用一个已有的id
放在onCreate()里,setContentView()后

Button button = (Button) findViewById(R.id.b01);
button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
Toast.makeText(MyButton.this, "我是Button!", Toast.LENGTH_SHORT).show();

}
});


一品梅 2011-02-24
  • 打赏
  • 举报
回复
帮顶一下,语言都是相通的,学得多联想就多思路就多,哈哈
wangtiantian23 2011-02-24
  • 打赏
  • 举报
回复
@+id是指增加一个id的意思,@id是指引用一个已有的id
zzxap 2011-02-24
  • 打赏
  • 举报
回复

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="giuz.blog1"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name="giuz.blog1.ActivityBlog1"
android:label="@string/app_name"
android:permission="giuz.permission.SEE">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<permission android:protectionLevel="normal" android:name="giuz.permission.SEE">
  </permission>

</manifest>
能否解析下这些界面代码的意思?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧