java 数字 字母 递增_java-如何在Android中递增字母数字?

这篇博客展示了如何在Android应用中通过编写代码动态更新TextView的内容,实现字母数字值的自动递增。主要涉及XML布局文件activity_main.xml的设置以及MainActivity.java中的Click事件处理,使用了一个简单的例子来解释这个过程。
摘要由CSDN通过智能技术生成

您不能直接增加字母数字值.如果要这样做,您需要为其编写一些代码行

这是activity_main.xml

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"

tools:context=".MainActivity"

android:orientation="vertical">

android:id="@+id/txt_autoincreament"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello World!"

app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintLeft_toLeftOf="parent"

app:layout_constraintRight_toRightOf="parent"

app:layout_constraintTop_toTopOf="parent" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="click"

android:onClick="Click"/>

这是MainActivity.java

public class MainActivity extends AppCompatActivity {

TextView autoTextIncreament;

String stringValue="ABB";

long intValue=20180001;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

autoTextIncreament = findViewById(R.id.txt_autoincreament);

}

public void Click(View view){

autoTextIncreament.setText(getValue());

}

private String getValue() {

return stringValue+String.valueOf(intValue++);

}

}

希望这会帮助你.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值