我将一个片段用于2种不同的活动,因为我像这样夸大了片段的布局
问题在于textview.setText(“”)方法不会改变textview的文本。
这是活动
public class CloverHome extends AppCompatActivity {
View inflatedView;
View mInflatedView;
LayoutInflater inflater;
TextView roomrate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clover_home);
inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(this).inflate(R.layout.impianapricing, null);
inflatedView = inflater.inflate(R.layout.facilitiesimpiana, viewGroup, false);
roomrate = viewGroup.findViewById(R.id.roomratet);
roomrate.setText(getString(R.string.temp));
BottomNavigationView bt = findViewById(R.id.nav2);
bt.setOnNavigationItemSelectedListener(navlistener);
getSupportFragmentManager().beginTransaction().replace(R.id.frame2, new room_frag()).commit(); }
private BottomNavigationView.OnNavigationItemSelectedListener navlistener =
new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
Fragment selected = null;
switch (menuItem.getItemId()) {
case R.id.roomf:
selected = new room_frag();
break;
case R.id.facility:
selected = new facilitiesimpiana();
break;
case R.id.contact:
selected = new impprice();
break;
}
roomrate.setText("new");
getSupportFragmentManager().beginTransaction().replace(R.id.frame2, Objects.requireNonNull(selected)).commit();
return true;
}
};
}
答案 0 :(得分:0)
尝试以下方法-
roomrate.setText(getActivity()
.getApplicationContext()
.getResources()
.getString(R.string.temp));