gpt4 book ai didi

java - 如何通过单击按钮更改 JAVA 中的字符串?

转载 作者:行者123 更新时间:2023-12-02 10:25:41 26 4
gpt4 key购买 nike

我的应用程序包含带有贴纸的键盘布局。所有贴纸都位于 recyclerView 内的“包”内。

如果我将 PACK_lib 的名称手动更改为包的名称(例如“allstickers”)并构建,那么它会起作用并仅显示“allstickers”的贴纸。

我可以用按钮来处理这个问题吗?我创建了两个按钮,b1b2

如果用户点击b1,它应该将Pack_lib字符串更改为“allstickers”。如果用户点击b2,它应该将Pack_lib字符串更改为“teststickers”。

单击按钮时,需要将 java 文件代码中的名称从“allstickers”更改为“teststickers”。

请帮忙。

我尝试提供按钮 ID 并使用 setText 代码。但这没有用。还尝试了 setVisibility 但也不起作用。

Stickers.java

private void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList[]=new String[0];
final String PACK_LIB = "allstickers";
final String PACK_APP="pack_app";
final String PACK_ICON="pack_on.png";
String curAssets="";

ma​​in_board_layout.xml

  <Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="allstickers"
/>

<Button
android:id="@+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="teststickers"
/>

用户应单击按钮,包应从“allstickers”切换到“teststickers”

最佳答案

要更改字符串,只需在按钮的 OnClick Listener 中更改字符串即可。

String sticker = "";

final Button button1 = (Button) findViewById(R.id.b1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

sticker = "allstickers";
}
});
final Button button2 = (Button) findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

sticker = "teststickers";
}
});

关于java - 如何通过单击按钮更改 JAVA 中的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53977769/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com