Skip to content

Commit

Permalink
change picture in SecondFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimin15 committed Apr 25, 2024
1 parent 438e375 commit e9c3d92
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
28 changes: 23 additions & 5 deletions app/src/main/java/com/example/proj2/Item_selection.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package com.example.proj2;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.navigation.fragment.NavHostFragment;

public class Item_selection extends AppCompatActivity {
Button m_btn;
ImageView imageView;
boolean i = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_item_selection);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;

Button button1 = findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Item_selection.this, SecondFragment.class);

//The transmission of data for image modification.
intent.putExtra("imageResourceId", R.drawable.doran_blade);

//move to SecondFragment
startActivity(intent);
}
});
}


}
10 changes: 9 additions & 1 deletion app/src/main/java/com/example/proj2/SecondFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,18 @@ public void onClick(View v) {
}
});

// Get the passed image resource id
int imageResourceId = getArguments().getInt("imageResourceId", -1);

}
// Set the image
if (imageResourceId != -1) {
ImageView imageView = view.findViewById(R.id.itemImage1);
imageView.setImageResource(imageResourceId);
}


}

@Override
public void onDestroyView() {
super.onDestroyView();
Expand Down

0 comments on commit e9c3d92

Please sign in to comment.