
[英]How can I automatically set a different text every day to a TextView in Android Studio? (which will set 24 hours and change at 12 pm automatically)
[英]how can i set text in textview by different buttons [duplicate]
在我的第一个活动中,我有多个按钮,而在第二个活动中,我只有一个文本视图,我想在每个按钮单击中设置文本,而且我的文本太长,所以我将它存储在 R.raw 目录中,我该怎么做
因为我是 Android 开发的新手,如果我犯了愚蠢的错误,请纠正我
这是我的第一个活动
switch (view.getId()){
case R.id.btn1:{
Intent i1=new Intent(this, Activity2.class);
startActivity(i1);
break;
}
case R.id.btn2:{
Intent i=new Intent(this, Activity2.class);
startActivity(i);
break;
}
case R.id.btn3:{
Intent i3=new Intent(this, Activity2.class);
startActivity(i3);
break;
}
这是我的第二个活动 xml 文件
xml
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingExtra="10dp"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center"
>
要从原始文件夹中的文本文件读取数据:
https://stackoverflow.com/a/6420426/3995126
InputStream inputStream = getResources().openRawResource(R.raw.yourtextfile);
BufferedReader bufferedReader= new BufferedReader(new InputStreamReader(inputStream));
String eachline = bufferedReader.readLine();
while (eachline != null) {
// `the words in the file are separated by space`, so to get each words
String[] words = eachline.split(" ");
eachline = bufferedReader.readLine();
}
将数据从一个 Activity 传递到另一个:
https://stackoverflow.com/a/2091482/3995126
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("KEY", "YourValue");
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.