Я хочу установить поля моей строки RecyclerView без использования xml, потому что иногда у меня есть две строки, и мне нужно динамически менять поля. Но когда я запускаю программу, маржа не устанавливается. Есть ли у кого-то ответ, что я сделал неправильно?Установить поля в адаптере RecyclerView без xml
Мой файл XML для понимания:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:focusable="true"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="@+id/settingTitle"
android:textColor="@color/colorBlack"
android:layout_width="match_parent"
android:textSize="16dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/settingSubtitle"
android:layout_below="@id/settingTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Это мой onBind от моего адаптера:
@Override
public void onBindViewHolder(MySettingHolder holder, int position) {
// Setting for one entry
Settings setting = settingList.get(position);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
// If the settingSubtitle is empty it should be not visible and just the settingTitle
if (setting.getSettingSubtitle().equals("")) {
params.setMargins(0, 18, 0, 18);
holder.settingTitle.setLayoutParams(params);
holder.settingTitle.setText(setting.getSettingTitle());
holder.settingSubtitle.setVisibility(View.GONE);
} else {
// Set Margins for settingTitle
params.setMargins(0, 18, 0, 18);
holder.settingTitle.setLayoutParams(params);
// Set Margins for settingSubtitle
params.setMargins(0, 0, 0, 18);
holder.settingSubtitle.setLayoutParams(params);
holder.settingTitle.setText(setting.getSettingTitle());
holder.settingSubtitle.setText(setting.getSettingSubtitle());
}
}
вы должны установить параметры для вашего recyclerview –
@santoshkumar И что вы думаете, что я здесь делаю? – ItsOdi1
recyclerview.setParams (params); –