Java 无法将片段显示为活动
您好,我正在尝试将我的片段加载到活动中,但无法将其加载。有人能告诉我我做错了什么吗?我的工具栏位于activity中,但我的片段包含一个来自Facebook的textview和profilepictureview。由于无法显示textview和profilepicture视图,我缺少了什么 下面是我的第一个_fragment.xml:Java 无法将片段显示为活动,java,android,xml,android-fragments,Java,Android,Xml,Android Fragments,您好,我正在尝试将我的片段加载到活动中,但无法将其加载。有人能告诉我我做错了什么吗?我的工具栏位于activity中,但我的片段包含一个来自Facebook的textview和profilepictureview。由于无法显示textview和profilepicture视图,我缺少了什么 下面是我的第一个_fragment.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentPic">
<TextView
android:id="@+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/users_FirstName"
android:textSize="@dimen/font_size"
android:hint="JJJJ"
android:layout_gravity="center_horizontal"/>
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/profilePic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
>
</com.facebook.login.widget.ProfilePictureView>
</LinearLayout>
secondActivity.java:
public class secondActivity extends AppCompatActivity {
private Intent intent;
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
intent = getIntent();
String firstName = intent.getStringExtra("firstName");
String userId = intent.getStringExtra("Id");
toolbar = (Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
toolbar.setLogo(R.drawable.ic_menu_image);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
我解决了问题,调用了错误的布局文件
View rootView = inflater.inflate(R.layout.event_fragment, container, false);
应该是:
View rootView = inflater.inflate(R.layout.first_fragment, container, false);
public class secondActivity extends AppCompatActivity {
private Intent intent;
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
intent = getIntent();
String firstName = intent.getStringExtra("firstName");
String userId = intent.getStringExtra("Id");
toolbar = (Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
toolbar.setLogo(R.drawable.ic_menu_image);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_second, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
View rootView = inflater.inflate(R.layout.event_fragment, container, false);
View rootView = inflater.inflate(R.layout.first_fragment, container, false);