I used constarintLayout as a container for mine recycleView, and I populate my elements depending on json (Verified Data).
So, I am doing some tricks here. If my restored json contains a specific value, I have to make some elements in the constraint layout in order to disappear and resize the others.
Everything works fine, but when I scroll down and scroll up, I do not need the changed value back to the old statue.
for ex: this marked row has a different configuration form

when scrolling down and scrolling up again, the line lost its changed shape:

Here is my constraintLayout.xml:
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:clickable="true"
android:focusable="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layout_constraintLeft_toRightOf="@+id/article_subtitle"
tools:layout_editor_absoluteY="27dp"
android:id="@+id/containerDetailsItem">
<TextView
android:id="@+id/technicalName"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="141dp"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:maxLines="1"
android:paddingLeft="5dp"
android:textColor="@color/white"
android:textSize="@dimen/text_main"
app:layout_constraintRight_toLeftOf="@+id/thumbnailLayout"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/technicalProfile"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="30dp"
android:background="@color/white"
android:drawableRight="@drawable/account_circle"
android:gravity="center"
android:maxLines="1"
android:text="الملف الشخصي"
android:padding="4dp"
android:textColor="@color/background"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintHorizontal_weight=".1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/technicalAge"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/technicalExperince"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="137dp"
android:layout_height="wrap_content"
android:layout_marginRight="19dp"
android:layout_marginTop="0dp"
android:maxLines="1"
android:textColor="@color/white"
app:layout_constraintRight_toLeftOf="@+id/thumbnailLayout"
app:layout_constraintTop_toBottomOf="@+id/technicalExperince" />
<TextView
android:id="@+id/technicalAge"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="139dp"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginRight="17dp"
android:layout_marginTop="2dp"
android:foregroundGravity="right"
android:gravity="right"
android:maxLines="1"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@+id/technicalExperince"
app:layout_constraintHorizontal_weight=".2"
app:layout_constraintRight_toLeftOf="@+id/thumbnailLayout"
app:layout_constraintTop_toBottomOf="@+id/technicalName"
app:layout_constraintVertical_bias="0.0" />
<RelativeLayout
android:id="@+id/thumbnailLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-36dp"
android:layout_marginRight="-1dp"
android:paddingBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/thumbnail"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_marginRight="5dp"
android:layout_marginTop="0dp"
android:background="@drawable/unselected"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</RelativeLayout>
And here is an example for changes to layout elements:
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("2")) {
holder.ageView.setTypeface(font);
holder.ageView.setText("\uf0ce" + " office" );
holder.experinceView.setVisibility(View.GONE);
holder.nameView.setTextSize(23);
}
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("1")) {
holder.ageView.setTypeface(font);
holder.ageView.setText( "\uf19c" + " company" );
holder.experinceView.setVisibility(View.GONE);
holder.nameView.setTextSize(23);
}
, , type .
type type, .
:
private class Adapter extends RecyclerView.Adapter<ViewHolder> {
public Adapter(Cursor cursor) {
mCursor = cursor;
}
@Override
public long getItemId(int position) {
mCursor.moveToPosition(position);
return mCursor.getLong(ArticleLoader.Query._ID);
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
View view = getLayoutInflater().inflate(R.layout.list_item_profiles_vertical, parent, false);
final ViewHolder vh = new ViewHolder(view);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW,
ItemsContract.Items.buildItemUri(getItemId(vh.getAdapterPosition()))));
try {
int i = Integer.parseInt((String) mCursor.getString(ArticleLoader.Query.SERVER_ID));
Log.i(TAG, "bindViews: " + i);
i = i + 1;
Config.BASE_URL = new URL("http:/json/users?user=" + mCursor.getString(ArticleLoader.Query.SERVER_ID));
startService(new Intent(DisplaysActivity.this, CurrentService.class));
Log.i(TAG, "onCreateDisplay: " + mCursor.getString(ArticleLoader.Query.SERVER_ID));
Log.i(TAG, "onClick: " + Config.BASE_URL);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
});
return vh;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.ageView.setTypeface(typeface);
mCursor.moveToPosition(position);
holder.nameView.setText(mCursor.getString(ArticleLoader.Query.NAME));
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("2")) {
holder.profileIcon.setTypeface(font);
holder.ageView.setTypeface(font);
holder.ageView.setText(" مكتب" );
holder.ageView.setTextSize(17);
holder.profileIcon.setText("\uf0f7");
holder.experinceView.setVisibility(View.GONE);
holder.nameView.setTextSize(23);
}
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("1")) {
holder.profileIcon.setTypeface(font);
holder.ageView.setTypeface(font);
holder.ageView.setText(" شركة");
holder.ageView.setTextSize(17);
holder.profileIcon.setText("\uf0f7");
holder.experinceView.setVisibility(View.GONE);
holder.nameView.setTextSize(23);
}
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("3")){
holder.profileIcon.setVisibility(View.GONE);
holder.ageView.setTypeface(typeface);
}
if (mCursor.getString(ArticleLoader.Query.TYPE).equals("3") && mCursor.getString(ArticleLoader.Query.STATUE).equals("1")){
holder.ageView.setText(mCursor.getString(ArticleLoader.Query.AGE) + " سنة" + " / " + "متاح ");
}else if(mCursor.getString(ArticleLoader.Query.TYPE).equals("3") && mCursor.getString(ArticleLoader.Query.STATUE).equals("0")){
holder.ageView.setText(mCursor.getString(ArticleLoader.Query.AGE) + " سنة" + " / " + "غير متاح ");
}else if (mCursor.getString(ArticleLoader.Query.TYPE).equals("3")){
holder.ageView.setText(mCursor.getString(ArticleLoader.Query.AGE) + " سنة");
}
holder.experinceView.setText(mCursor.getString(ArticleLoader.Query.EXPERINCE) + " سنوات خبرة" + " / " + mCursor.getString(ArticleLoader.Query.CITY));
if (mCursor.getString(ArticleLoader.Query.THUMB_URL).length() > 5) {
Picasso.with(getApplicationContext()).load(mCursor.getString(ArticleLoader.Query.THUMB_URL)).into(holder.thumbnailView);
} else {
Picasso.with(getApplicationContext()).load("http:logo.png").into(holder.thumbnailView);
}
holder.nameView.setTypeface(typeface);
holder.experinceView.setTypeface(typeface);
holder.technicalProfile.setTypeface(typeface);
}
@Override
public int getItemCount() {
if (mCursor.getCount() < 1){
Toast.makeText(DisplaysActivity.this, "لا يوجد محتوى", Toast.LENGTH_SHORT).show();
}
return mCursor.getCount();
}
}
, , ,
?