我有一个活动MarkerDetailedActivity,它应该显示有关标记的所有信息(照片/日期/作者/描述/标题)。问题是代码认为mDateTextView
是mDescriptionTextView
。但是在xml文件中,所有内容都写得正确。
我的xml设计屏幕
MarkerDetailedActivity.class
public class MarkerDetailsActivity extends AppCompatActivity {
private static final String EXTRA_MARKER = "marker";
public static Intent getStartIntent(Context context, Marker marker) {
Intent startIntent = new Intent(context, MarkerDetailsActivity.class);
startIntent.putExtra(EXTRA_MARKER, marker);
return startIntent;
}
ImageView mImageView;
TextView mNameTextView;
TextView mAuthorTextView;
TextView mDateTextView;
TextView mDescriptionTextView;
Marker mMarker;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details_marker);
mMarker = getIntent().getParcelableExtra(EXTRA_MARKER);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle(mMarker.getName());
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
onBackPressed();
}
});
mImageView = findViewById(R.id.image_view);
mDateTextView = findViewById(R.id.text_view_date);
mAuthorTextView = findViewById(R.id.text_view_author);
mDescriptionTextView = findViewById(R.id.text_view_description);
bindMarker(mMarker);
}
private void bindMarker(Marker marker) {
Picasso.with(mImageView.getContext())
.load(marker.getImage().getUrl())
.into(mImageView);
mAuthorTextView.setText(marker.getAuthor());
mDescriptionTextView.setText(marker.getDescription());
mDateTextView.setText(marker.getDate());
}
}
这是我的xml文件 activity_details_marker.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="224dp"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
tools:src="@drawable/imag0162" />
<View
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/bg_black_gradient"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_collapseMode="pin"
app:navigationIcon="@drawable/ic_arrow_back_white_24dp"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/text_view_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/blue_a400"
android:drawablePadding="8dp"
tools:text="Danik Fedirko" />
<TextView
android:id="@+id/text_view_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textColor="@color/blue_a400"
android:textAppearance="?android:textAppearanceMedium"
android:drawablePadding="8dp"
tools:text="2018/02/02" />
<TextView
android:id="@+id/text_view_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textColor="@color/black"
tools:text="Lorem ipsum dolor si amet"
android:textAppearance="?android:textAppearanceMedium"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
如何解决这个问题?
答案 0 :(得分:0)
检查您的模型类标记。 您将访问日期方法设为:
String date;
String description;
public String getDate(){
return description;
}
或者你可能在日期方法中设置描述
String date;
String description;
public void setDate(String s){
description = s;
}
反之亦然
最好的方法是不要在课堂上右键单击任何方法并选择getter和setter。
答案 1 :(得分:0)
检查您的标记实例,并将其作为包裹传递到您的位置。您必须在date属性中传递描述。确保在标记对象属性中传递正确的值。