public class F1 extends Fragment {
private View view;
public Find_button find_button;
public void getFind_button(Find_button find_button) {
this.find_button = find_button;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
view = inflater.inflate(R.layout.f1, null);
return view;
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
find_button.button(view);
}
}
interface Find_button {
void button(View view);
}
-----------------------------------
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addf1();
}
protected void addf1() {
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
F1 f1 = new F1();
fragmentTransaction.add(R.id.f1, f1, "f1");
fragmentTransaction.commit();
f1.getFind_button(new Find_button() {
@Override
public void button(View view) {
final Button button = view.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
button.setText("F1.Button");
Toast.makeText(MainActivity.this, "F1.Button", Toast.LENGTH_SHORT).show();
}
});
}
});
}
}
0 件のコメント:
コメントを投稿