Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4 #542 第四次实验 #1337

Merged
merged 1 commit into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions students/soft1714080902420/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".Soft1714080902420SearceActivity"></activity>
<activity android:name=".Soft1714080902420SourceActivity" />
<activity android:name=".Soft1714080902420Activity">
<activity
android:name=".Soft1714080902420Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,96 @@
package edu.hzuapps.androidlabs.soft1714080902420;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;

public class Soft1714080902420Activity extends AppCompatActivity {
private BottomNavigationView bottomNavigationView;
private searceFragment fragment1;
private sourceFragment fragment2;
private newsFragment fragment3;
private Fragment[] fragments;
private int lastfragment;//用于记录上个选择的Fragment

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_1714080902420_activity);
Button bt1 = (Button) findViewById(R.id.button1);
Button bt2=(Button)findViewById(R.id.button2);
bt1.setOnClickListener(listener);
bt2.setOnClickListener(listener2);
initFragment();
}

//初始化fragment和fragment数组
private void initFragment() {

fragment1 = new searceFragment();
fragment2 = new sourceFragment();
fragment3 = new newsFragment();
fragments = new Fragment[]{fragment1, fragment2, fragment3};
lastfragment = 0;
getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment1).show(fragment1).commit();
bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);

bottomNavigationView.setOnNavigationItemSelectedListener(changeFragment);
}

Button.OnClickListener listener = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Soft1714080902420Activity.this, Soft1714080902420SourceActivity.class);
startActivity(intent);
Soft1714080902420Activity.this.finish();
//判断选择的菜单
private BottomNavigationView.OnNavigationItemSelectedListener changeFragment = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {

switch (item.getItemId()) {
case R.id.navigation_home: {
if (lastfragment != 0) {
switchFragment(lastfragment, 0);
lastfragment = 0;

}

return true;
}
case R.id.navigation_dashboard: {
if (lastfragment != 1) {
switchFragment(lastfragment, 1);
lastfragment = 1;

}

return true;
}
case R.id.navigation_notifications: {
if (lastfragment != 2) {
switchFragment(lastfragment, 2);
lastfragment = 2;

}

return true;
}


}


return false;
}
};
Button.OnClickListener listener2 = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Soft1714080902420Activity.this, Soft1714080902420SearceActivity.class);
startActivity(intent);
Soft1714080902420Activity.this.finish();

//切换Fragment
private void switchFragment(int lastfragment, int index) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.hide(fragments[lastfragment]);//隐藏上个Fragment
if (fragments[index].isAdded() == false) {
transaction.add(R.id.container, fragments[index]);


}
};
transaction.show(fragments[index]).commitAllowingStateLoss();


}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.hzuapps.androidlabs.soft1714080902420;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class newsFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_news, container, false);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.hzuapps.androidlabs.soft1714080902420;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class searceFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_searce, container, false);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package edu.hzuapps.androidlabs.soft1714080902420;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


public class sourceFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_source, container, false);
}

}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Loading