データを取得するための機能実装

This commit is contained in:
nero 2023-12-20 12:52:24 +09:00
parent e34dd65dda
commit 9d108212dd
2 changed files with 37 additions and 2 deletions

View File

@ -1,11 +1,26 @@
package one.nem.lacerta.feature.library; package one.nem.lacerta.feature.library;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
public class LibraryXFragment extends Fragment { public class LibraryXFragment extends Fragment {
// フラグメントが作成された際に呼ばれるメソッド private TextView textView; // フィールドとして TextView を定義
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_library_file, container, false);
textView = view.findViewById(R.id.textView);
return view;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -14,7 +29,10 @@ public class LibraryXFragment extends Fragment {
if (getArguments() != null) { if (getArguments() != null) {
String receivedData = getArguments().getString("key_name"); String receivedData = getArguments().getString("key_name");
// ここで receivedData を使って何か処理を行う // onCreateView メソッドで取得した TextView にデータをセットする
if (textView != null) {
textView.setText(receivedData);
}
} }
} }

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginEnd="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>