Android中点击按钮获取星级评分条的评分
场景
效果

注:
博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
实现
将布局改为LinearLayout,并通过android:orientation="vertical">设置为垂直布局,然后添加一个RatingBar,并通过
android:rating=""
设置其星数为5
然后再添加一个Button,分别给他们添加Id。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".RatingBarActivity"> <RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating=""
/> <Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF5000"
android:text="发表评价"
/> </LinearLayout>
然后来到Activity,通过Id获取RatingBar和Button,在button的点击事件中,获取星级数,并提示。
packagecom.badao.relativelayouttest; importandroidx.appcompat.app.AppCompatActivity; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RatingBar;
importandroid.widget.Toast; public class RatingBarActivity extends AppCompatActivity {
private RatingBarratingBar; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rating_bar);
ratingBar = (RatingBar) findViewById(R.id.ratingBar);
Button button = (Button) findViewById(R.id.btn);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
float rating = ratingBar.getRating();
Toast.makeText(RatingBarActivity.this,"你的评分为:"+rating+"分",Toast.LENGTH_SHORT).show();;
}
});
}
}
Android中点击按钮获取星级评分条的评分的更多相关文章
- Android中点击按钮获取string.xml中内容并弹窗提示
场景 AndroidStudio跑起来第一个App时新手遇到的那些坑: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103797 ...
- Android中点击按钮启动另一个Activity以及Activity之间传值
场景 点击第一个Activity中的按钮,启动第二个Activity,关闭第二个Activity,返回到第一个Activity. 在第一个Activity中给第二个Activity传递值,第二个Act ...
- Android中点击隐藏软键盘最佳方法——Android开发之路4
Android中点击隐藏软键盘最佳方法 实现功能:点击EditText,软键盘出现并且不会隐藏,点击或者触摸EditText以外的其他任何区域,软键盘被隐藏: 1.重写dispatchTouchEve ...
- Android 中点击返回键弹出“在按一次退出程序”的做法
在很多应用中都有这种做法,连续点击两次才退出程序,目的是为了防止用户不小心点击到了返回键而退出程序了,添加了一次用户确认的过程. 其实做法很简单,只需要做一个延时的消息处理就可以了. 首先在我们在一个 ...
- 微信小程序开发——点击按钮获取用户授权没反应或反应很慢的解决方法
异常描述: 点击按钮获取用户手机号码,有的时候会出现点击无反应或很久之后才弹出用户授权获取手机号码的弹窗,这种情况下,也会出现点击穿透的问题(详见:微信小程序开发——连续快速点击按钮调用小程序api返 ...
- Android点击按钮拨打电话
代码改变世界 Android点击按钮拨打电话 public void callPhone(String str) { Intent intent=new Intent(); intent.setAct ...
- Android中点击事件的四种写法详解
Android中点击事件的四种写法 使用内部类实现点击事件 使用匿名内部类实现点击事件 让MainActivity实现View.OnClickListener接口 通过布局文件中控件的属性 第一种方法 ...
- 使用Android点击按钮跳转页面
1.首先新建一个Android工程,命名为MyApp(名字可以自己随意起); 2.以原有的MainActivity.java文件为登录界面,然后在src文件中的包上面右击选择New目录下的Other中 ...
- Py3+PyQt5+Eric6:学习记录之第一天:点击按钮获取文本框的值并输出。
一.使用qt designer拖拽界面. 使用qtdesigner拖拽界面:
随机推荐
- Windows 系统安装 Python 3.8 详解
安装 Python 很简单,但是其中的很多细节未必大家都清楚,趁着给自己安装最新 3.8 版本,把整个过程详细记录下. Python or Anaconda 本节是专门写给一些小白,Python 还没 ...
- Redhat6.7 切换Centos yum源
转自:http://inlhx.iteye.com/blog/2336729 RedHat 更换Yum源 1.检查yum包 rpm -qa |grep yum 2.删除自带包 rpm -aq | gr ...
- xhsell关闭jupyter仍然运行的命令
nohup jupyter notebook & nohup 和 &都是linux的命令 1.& 当在前台运行某个作业时,终端被该作业占据:可以在命令后面加上& 实现后 ...
- 每天一道Java题[9]
题目 native关键字的作用是什么? 解答 首先,需了解JNI(Java Native Interface),它是连接Java平台与本地C代码的一个API. 其次,用native关键字声明的方法,是 ...
- IntelliJ IDEA 2019.3 安装+永久破解[Windows]
IntelliJ IDEA 2019的最后一个版本发布了,听说大幅优化了运行速度,本人实测启动速度确实比以前快不少,所以赶紧安排上新版本IDEA的破解教程 系统环境:Win10 LTSC(1809) ...
- centos最小化安装时网络配置
查看网卡: ip addr 修改网络配置文件 vi /etc/sysconfig/network-scripts/ifcfg-enp33 BOOTPROTO=dhcp ONBOOT=yes 重启网络服 ...
- 15、WAN
WAN wide area network 覆盖较大地理范围的数据通信网络使用网络提供商和电信公司所提供的传输设施传输数据 通过不同WAN协议,将LAN延伸到远程站点的其他LAN广域网接入处于OSI七 ...
- 利用Atomic, ThreadLocal, 模仿AQS, ReentrantLock
/** * @description 队列同步器,利用原子整形模仿AQS,非公平锁(简单自适应自旋) * @since 2020/2/4 */ public class QueueSynchroniz ...
- Linux内核单链表
主要说明Linux内核中单链表操作的关键思想,需要注意的地方 1. 假设 为了说明关键思想,对数据结构进行了精简 2. 数据结构定义 struct ListNode { int val; ListNo ...
- wordpress 如何防止盗链
盗链是指其它站点使用了你自己网站的图片音乐等资源,然后链接又没有更换,直接显示的就是你站点的图片,这在转载文章时最常见,比如转载时将 整篇文章都转载过去,包括文章里面的图片,有些人就懒得把图片再重新上 ...