说明:android循环控件,注册和显示内容
效果图:
step1: E:\projectgood\resget\demozz\IosDialogDemo-main\app\src\main\java\com\example\iosdialogdemo\TimerActivity.java
package com.example.iosdialogdemo;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.Arrays;
public class TimerActivity extends AppCompatActivity {
private TextView tv_img0,tv_img1,tv_img2,tv_img3,tv_img4;
private int[] tvIds = {R.id.tv_img0,R.id.tv_img1,R.id.tv_img2,R.id.tv_img3,R.id.tv_img4};
private TextView[] tvGroups = {tv_img0,tv_img1,tv_img2,tv_img3,tv_img4};
private int[] ages = {0,1,2,3,4};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_same);
for (int i=0;i<tvIds.length;i++){
tvGroups[i] =findViewById(tvIds[i]);
tvGroups[i].setText(String.valueOf(ages[i]));
}
}
}
step2: E:\projectgood\resget\demozz\IosDialogDemo-main\app\src\main\res\layout\activity_same.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_bright">
<TextView
android:id="@+id/tv_img0"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@android:color/holo_red_dark"
android:textSize="50sp"
/>
<TextView
android:id="@+id/tv_img1"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@android:color/holo_orange_dark"
android:textSize="50sp"
/>
<TextView
android:id="@+id/tv_img2"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@android:color/holo_blue_light"
android:textSize="50sp"
/>
<TextView
android:id="@+id/tv_img3"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@android:color/holo_green_light"
android:textSize="50sp"
/>
<TextView
android:id="@+id/tv_img4"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@android:color/holo_purple"
android:textSize="50sp"
/>
</LinearLayout>
end