setText()
值显示在LOGCAT
但未显示在Layout.Strange行为中。是否有任何人遇到此问题?我们将非常感谢任何帮助。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
//set ViewPagerIndicatorView
this.viewPagerIndicatorView = (ViewPagerIndicatorView) findViewById(R.id.viewpager_indicator_view);
final Map<String, View> map = new HashMap<String, View>();
map.put("About", LayoutInflater.from(this).inflate(R.layout.activity_sample_pager_2, null));
map.put("Locations", LayoutInflater.from(this).inflate(R.layout.activity_sample_pager_1, null));
map.put("Reviews", LayoutInflater.from(this).inflate(R.layout.activity_sample_pager_0, null));
this.viewPagerIndicatorView.setupLayout(map);
LayoutInflater factory = getLayoutInflater();
layout = factory.inflate(R.layout.activity_sample_pager_0, null);
View linearLayout = layout.findViewById(R.id.LinearLayout1);
linearLayout.setVisibility(View.VISIBLE);
Loading();
}
public void Loading(){
String Value="My Name Is";
Tv1=(TextView)layout.findViewById(R.id.TvBasicInfoFP);
Tv1.setVisibility(View.VISIBLE);
Tv1.setText(String.valueOf(Value));
Log.d("TextView",Value);
}
答案 0 :(得分:1)
仅仅夸大布局是不够的:
layout = factory.inflate(R.layout.activity_sample_pager_0, null);
它还没有显示给你。
必须将其添加到根视图中:
LinearLayout rootLayout = findViewById(R.id.rootLayout);
rootLayout.addView(layout);
在您的activity_my.xml
中,您的根布局带有ID,如下所示:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</LinearLayout>