android底部导航栏如何实现页面跳转功能
时间: 2023-09-16 17:12:53 浏览: 109
android实现页面跳转
++) {
printf("\t%d", students[i].scores[j]);
}
printf("\t%d\t%.2f\n", students[i].totalScore, students[i].averageScore);
for(int j = 0; j < subjectCount; j++) {
printfAndroid底部导航栏可以使用TabLayout和ViewPager组合实现页面跳转功能。
首先,在布局文件中定义("请输入%s成绩:", subjects[j]);
scanf("%d", &students[i].scores[j]);
students[i].totalScore += students[i].scores[j];
}
students[i].averageScore = (float)students[i].totalScore / subjectCount;
TabLayout和ViewPager:
```xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
printf("学生成绩已成功修改!\n");
break;
}
}
if(!found) {
printf android:layout_height="match_parent">
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
android("学号不存在!\n");
}
}
// 删除学生成绩
void deleteStudent() {
if(studentCount == 0:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior) {
printf("没有学生信息!\n");
return;
}
char id[MAX_ID_LEN];
int found = 0;
printf("请输入学号:");
scanf("%s", id);
for(int i = 0; i < student"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
Count; i++) {
if(strcmp(students[i].id, id) == 0) {
found = 1;
for android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabIndicatorColor="@color/colorAccent(int j = i; j < studentCount - 1; j++) {
students[j] = students[j + 1];
}
"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@android:color/white"/>
</androidx.coordinator studentCount--;
printf("学生成绩已成功删除!\n");
break;
}
}
if(!foundlayout.widget.CoordinatorLayout>
```
然后,创建Fragment并创建FragmentPagerAdapter,将FragmentPagerAdapter设置到ViewPager中:
```java) {
printf("学号不存在!\n");
}
}
// 统计学生成绩
void calculateStats() {
if
public class MyPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MyPagerAdapter(@NonNull FragmentManager fm, List(studentCount == 0) {
printf("没有学生信息!\n");
return;
}
float averageScores[MAX_SUBJECTS] = {0};
float totalAverageScore = 0;
printf("科目名称\t平均分\n");
<Fragment> fragments) {
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
this.fragments = fragments;
}
@ for(int i = 0; i < subjectCount; i++) {
for(int j = 0; j < studentCount; jNonNull
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int++) {
averageScores[i] += students[j].scores[i];
}
averageScores[i] /= studentCount;
printf("% getCount() {
return fragments.size();
}
}
public class MainActivity extends AppCompatActivity {
private ViewPager viewPager;
private TabLayout tabLayouts\t\t%.2f\n", subjects[i], averageScores[i]);
}
for(int i = 0; i < studentCount; i++) {
totalAverageScore += students[i].averageScore;
}
totalAverageScore /= studentCount;
printf(";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager =总平均分:%.2f\n", totalAverageScore);
}
// 保存学生成绩到文件
void saveToFile() {
if(studentCount == 0) {
printf("没有学生信息!\n");
return;
}
FILE *fp findViewById(R.id.viewPager);
tabLayout = findViewById(R.id.tabLayout);
List<Fragment> fragments = new ArrayList<>();
fragments;
char filename[MAX_NAME_LEN];
printf("请输入文件名:");
scanf("%s", filename);
fp = fopen(filename.add(new FragmentA());
fragments.add(new FragmentB());
fragments.add(new FragmentC());
viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(),, "w");
fprintf(fp, "学号\t姓名");
for(int i = 0; i < subjectCount; i++) fragments));
tabLayout.setupWithViewPager(viewPager);
}
}
```
最后,在Fragment中实现具体的页面功能。
阅读全文