У меня есть проблема, когда я изменяю какое-то значение, например, удаляю комментарий в моем обзоре переработчика, он не обновляется автоматически, Google говорит, что используйте LiveData DataBinding RecyclerView, кто-нибудь когда-либо делает привязку данных RecyclerView LiveData, пожалуйста, помогите мне
Это мой MainActivity.java
public class TabDetailHotActivity extends AppCompatActivity {
//GLOBAL
public static MainActivity mainActivity_;
TextView TVGameDate;
TextView TVGameTitle;
ImageView IMGGameImage;
TextView TVSeenCounter;
TextView TVCommentCounter;
TextView TVLikeCounter;
ImageView IMGSeenView;
ImageView IMGCommentView;
ImageView IMGLikeView;
ImageView ICONHotTrendingNewsSaving;
//EVENT BUS
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(MainActivity.EventStoredMessageTrending event) {
getMessageTrendingMainActivity(event.SendMessageUrutan, event.SendTotalThread, event.SendMessageIDComment, event.SendMessageComment, event.SendMessageEntryTime, event.SendMessageisEdited, event.SendMessageEditTime);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(MainActivity.EventStoredMessageTrendingLogin event) {
getMessageTrendingLoginMainActivity(event.SendMessageUrutan, event.SendTotalThread, event.SendMessageIDComment, event.SendMessageComment, event.SendMessageEntryTime, event.SendMessageisEdited, event.SendMessageEditTime, event.SendMessageEditable);
}
public void getMessageTrendingMainActivity(int ReceivedMessageUrutan, int ReceivedTotalThread, String ReceivedMessageIDComment, String ReceivedMessageComment, String ReceivedMessageEntryTime, int ReceivedMessageEdited, String ReceivedMessageEditTime){
Toast.makeText(this, "Load Comment Not Login :( >> ReceivedMessageComment:"+ReceivedMessageComment+", Toast.LENGTH_LONG).show();
}
public void getMessageTrendingLoginMainActivity(int ReceivedMessageUrutan, int ReceivedTotalThread, String ReceivedMessageIDComment, String ReceivedMessageComment, String ReceivedMessageEntryTime, int ReceivedMessageEdited, String ReceivedMessageEditTime, int ReceivedMessageEditable){
Toast.makeText(this, "Load Comment Login :) >> ReceivedMessageComment:" + ReceivedMessageComment, Toast.LENGTH_LONG).show();
createDummyDataComment(ReceivedMessageUrutan, ReceivedTotalThread, ReceivedMessageIDComment, ReceivedMessageComment, ReceivedMessageEntryTime, ReceivedMessageEdited, ReceivedMessageEditTime, ReceivedMessageEditable);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitydetail_tabhot);
ToolbarX = findViewById(R.id.toolbar);
setSupportActionBar(ToolbarX);
getSupportActionBar().setTitle("");
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final CollapsingToolbarLayout collapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle("");
Intent intent = getIntent();
mDummyIDContent = intent.getStringExtra("DummyIDContentPKG");
mDummyTitle = intent.getStringExtra("DummyTitlePKG");
mDummyPublishTime = intent.getStringExtra("DummyPublishTimePKG");
mDummyImageOriPKG = intent.getStringExtra("DummyImageOriPKG");
mDummyShortDescription = intent.getStringExtra("DummyShortDescriptionPKG");
mDummySeen = intent.getIntExtra("DummySeenPKG", 0);
mDummyComment = intent.getIntExtra("DummyCommentPKG", 0);
mDummyLike = intent.getIntExtra("DummyLikePKG", 0);
mDummyisComment = intent.getIntExtra("DummyisCommentPKG", 0);
mDummyisLike = intent.getIntExtra("DummyisLikePKG", 0);
mDummyisBookmark = intent.getIntExtra("DummyisBookmarkPKG", 0);
date_Behaviour = findViewById(R.id.date_behavior);
IMGGameImage = findViewById(R.id.backdrop);
TVGameDate = findViewById(R.id.date);
TVGameTitle = findViewById(R.id.title);
TVSeenCounter = findViewById(R.id.TV_SeenCounter);
TVCommentCounter = findViewById(R.id.TV_CommentCounter);
TVLikeCounter = findViewById(R.id.TV_LikeCounter);
RequestOptions requestOptions = new RequestOptions();
requestOptions.error(UtilsNews.getRandomDrawbleColor());
TVGameDate.setText(mDummyPublishTime);
TVGameTitle.setText(mDummyTitle);
TVSeenCounter.setText(String.valueOf(mDummySeen));
TVCommentCounter.setText(String.valueOf(mDummyComment));
TVLikeCounter.setText(String.valueOf(mDummyLike));
Glide.with(this)
.load(mDummyImageOriPKG)
.apply(requestOptions)
.transition(DrawableTransitionOptions.withCrossFade())
.into(IMGGameImage);
/* initWebView(mUrl);*/
ImageButton BTNSendMessageDetailHotTrendingNews = findViewById(R.id.BTN_SendMessageDetailHotTrendingNews);
final TextView ETSendMessageDetailHotTrendingNews = findViewById(R.id.ET_SendMessageDetailHotTrendingNews);
BTNSendMessageDetailHotTrendingNews.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String TheMessage = ETSendMessageDetailHotTrendingNews.getText().toString();
if(!TheMessage.equals("")){
if(mainActivity_!=null) {
mainActivity_.rncryptorLoadSendEditDelete("SendComment", mDummyIDContent, TheMessage);
}
}else{
Toast.makeText(TabDetailHotActivity.this, "You don't send anything", Toast.LENGTH_SHORT).show();
}
ETSendMessageDetailHotTrendingNews.setText("");
}
});
//
if(mainActivity_!=null) {
mainActivity_.rncryptorLoadSendEditDelete("LoadComment", mDummyIDContent, "");
}
}
private void initWebView(String url) {
WebView webView = findViewById(R.id.webView);
webView.getSettings().setLoadsImagesAutomatically(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
}
ArrayList<ModelDetailHotTrendingNewsComment> modelDetailHotTrendingNewsComments = new ArrayList<ModelDetailHotTrendingNewsComment>();
AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener listenerDetailHotTrendingNewsComment;
public void createDummyDataComment(int ReceivedMessageUrutan, int ReceivedTotalThread, final String ReceivedMessageIDComment, String ReceivedMessageComment, String ReceivedMessageEntryTime, int ReceivedMessageEdited, String ReceivedMessageEditTime, int ReceivedMessageEditable) {
modelDetailHotTrendingNewsComments.add(new ModelDetailHotTrendingNewsComment(ReceivedMessageIDComment,ReceivedMessageComment,ReceivedMessageEntryTime,ReceivedMessageEditable,ReceivedMessageEditTime));
if(ReceivedMessageUrutan == ReceivedTotalThread-1){
listenerDetailHotTrendingNewsComment = new AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener(){
@Override
public void onRowDetailHotTrendingNewsContainerClick(View view, int position) {
}
@Override
public void onRowMessageEditClick(View view, int position) {
}
@Override
public void onRowMessageDeleteClick(View view, final int position) {
String[] YOURCHOICE = {"Yes", "No"};
AlertDialog.Builder builder = new AlertDialog.Builder(TabDetailHotActivity.this);
builder.setTitle("Do you want to delete this comment?");
builder.setItems(YOURCHOICE, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == 0){
Toast.makeText(TabDetailHotActivity.this, "Deleted Successfully!", Toast.LENGTH_SHORT).show();
if(mainActivity_!=null) {
mainActivity_.rncryptorLoadSendEditDelete("DeleteComment", modelDetailHotTrendingNewsComments.get(position).getIdcontent(), "");
}
}else if(which == 1){
Toast.makeText(TabDetailHotActivity.this, "You don't delete the Comment", Toast.LENGTH_SHORT).show();
}
}
});
builder.show();
}
};
RecyclerView RVDetailHotTrendingNewsComment = findViewById(R.id.RVDetail_HotTrendingNewsComment);
RVDetailHotTrendingNewsComment.setHasFixedSize(true);
AdapterDetailHotTrendingNewsComment adapterDetailHotTrendingNewsComment = new AdapterDetailHotTrendingNewsComment(this, modelDetailHotTrendingNewsComments, listenerDetailHotTrendingNewsComment);
RVDetailHotTrendingNewsComment.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
RVDetailHotTrendingNewsComment.setAdapter(adapterDetailHotTrendingNewsComment);
//Optimized
RVDetailHotTrendingNewsComment.setHasFixedSize(true);
RVDetailHotTrendingNewsComment.setItemViewCacheSize(20);
}
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
@Override
public void onBackPressed() {
super.onBackPressed();
supportFinishAfterTransition();
}
//EVENTBUS
@Override
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
}
@Override
public void onStop() {
EventBus.getDefault().unregister(this);
super.onStop();
}
}
Это мой activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/darkgrey"
tools:context=".TabDetailHotActivity">
<androidx.core.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:background="@color/darkgrey"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:background="@color/darkgrey"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:textColor="@color/colorWhite"
android:textStyle="bold"
android:fontFamily="sans-serif-light"
android:textSize="19sp"
android:text="Title of News"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@id/title"
android:textColor="@color/colorWhite"
android:layout_marginTop="10dp"
android:maxLines="1"
android:drawablePadding="10dp"
android:singleLine="true"
android:ellipsize="end"
android:text="a time ago" />
<ImageView
android:id="@+id/IMG_SeenView"
android:src="@drawable/watch"
android:layout_marginLeft="8dp"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/TV_SeenCounter"
android:paddingTop="2dp"
android:layout_marginTop="1dp"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/TV_SeenCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/IMG_CommentView"
android:text="999"
android:layout_marginTop="2dp"
android:textSize="14dp"
android:textColor="@color/white"
android:paddingLeft="@dimen/small_intrinsic_padding"
android:textAppearance="@style/TextAppearance.Second.Light" />
<ImageView
android:id="@+id/IMG_CommentView"
android:src="@drawable/comment_off"
android:layout_toLeftOf="@id/TV_CommentCounter"
android:layout_alignParentBottom="true"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="2dp"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/TV_CommentCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/IMG_LikeView"
android:layout_marginTop="2dp"
android:text="999"
android:textSize="14dp"
android:textColor="@color/white"
android:paddingLeft="@dimen/small_intrinsic_padding"
android:textAppearance="@style/TextAppearance.Second.Light" />
<ImageView
android:id="@+id/IMG_LikeView"
android:src="@drawable/heart_off"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@id/TV_LikeCounter"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginTop="4dp"
android:layout_marginLeft="5dp"
android:layout_marginBottom="2dp"
android:scaleType="centerInside"
android:adjustViewBounds="true"/>
<TextView
android:id="@+id/TV_LikeCounter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_alignParentEnd="true"
android:text="999"
android:textSize="14dp"
android:layout_alignParentBottom="true"
android:textColor="@color/white"
android:paddingLeft="@dimen/small_intrinsic_padding"
android:textAppearance="@style/TextAppearance.Second.Light" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darkgrey">
<ProgressBar
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/progress_bar"
android:layout_marginTop="50dp"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<WebView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/RL_Bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:background="#FFFFFF"
android:layout_alignParentBottom="true">
<EditText
android:id="@+id/ET_SendMessageDetailHotTrendingNews"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:hint="Type a comment..."
android:layout_toLeftOf="@id/BTN_SendMessageDetailHotTrendingNews"
android:layout_centerVertical="true"/>
<ImageButton
android:id="@+id/BTN_SendMessageDetailHotTrendingNews"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_send_black_24dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/darkgrey">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RVDetail_HotTrendingNewsComment"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<FrameLayout
android:id="@+id/date_behavior"
app:layout_anchor="@+id/appbar"
app:behavior_autoHide="true"
android:adjustViewBounds="true"
app:layout_anchorGravity="right|end|bottom"
android:clickable="false"
android:background="@drawable/round_white"
android:layout_width="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginBottom="410dp"
android:layout_height="wrap_content"
tools:ignore="UnusedAttribute">
<ImageView
android:src="@drawable/ic_date"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"/>
<TextView
android:textColor="#606060"
android:id="@+id/date"
android:layout_marginLeft="27dp"
android:layout_marginRight="10dp"
android:text="01 January 1990"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Это AdapterComment.java
public class AdapterDetailHotTrendingNewsComment extends RecyclerView.Adapter {
private Context mContext;
private ArrayList<ModelDetailHotTrendingNewsComment> modelDetailHotTrendingNewsComments;
private AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener mListener;
public AdapterDetailHotTrendingNewsComment(Context mContext, ArrayList<ModelDetailHotTrendingNewsComment> modelDetailHotTrendingNewsComments, AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener mListener) {
this.mContext = mContext;
this.modelDetailHotTrendingNewsComments = modelDetailHotTrendingNewsComments;
this.mListener = mListener;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.itemdetail_hottrendingnewscomment, null);
return new DetailHotTrendingNewsViewHolder(v, mListener);
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
final DetailHotTrendingNewsViewHolder detailHotTrendingNewsViewHolder = (DetailHotTrendingNewsViewHolder) holder;
final ModelDetailHotTrendingNewsComment modelDetailHotTrendingNewsCommentX = modelDetailHotTrendingNewsComments.get(position);
Glide.with(mContext).load(modelDetailHotTrendingNewsCommentX.getMessageimage()).into(detailHotTrendingNewsViewHolder.IMGMessageImage);
detailHotTrendingNewsViewHolder.TVMessageUsername.setText(modelDetailHotTrendingNewsCommentX.getMessageusername());
detailHotTrendingNewsViewHolder.TVMessageDescription.setText(modelDetailHotTrendingNewsCommentX.getMessagedescription());
detailHotTrendingNewsViewHolder.TVMessageDate.setText(modelDetailHotTrendingNewsCommentX.getMessagedate());
}
@Override
public int getItemCount() {
int itemCount = modelDetailHotTrendingNewsComments.size();
return itemCount;
}
public class DetailHotTrendingNewsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
ImageView IMGMessageImage;
TextView TVMessageUsername;
TextView TVMessageDescription;
TextView TVMessageDate;
private RelativeLayout ROWDetailHotTrendingNewsContainer;
TextView TVMessageEdit;
ImageView IMGMessageDelete;
private AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener mListener;
public DetailHotTrendingNewsViewHolder(View itemView, AdapterDetailHotTrendingNewsComment.RecyclerViewClickListener listener) {
super(itemView);
IMGMessageImage = itemView.findViewById(R.id.IMG_MessageImage);
TVMessageUsername = itemView.findViewById(R.id.TV_MessageUsername);
TVMessageDescription = itemView.findViewById(R.id.TV_MessageDescription);
TVMessageDate = itemView.findViewById(R.id.TV_MessageDate);
ROWDetailHotTrendingNewsContainer = itemView.findViewById(R.id.ROW_DetailHotTrendingNewsContainer);
TVMessageEdit = itemView.findViewById(R.id.TV_MessageEdit);
IMGMessageDelete = itemView.findViewById(R.id.IMG_MessageDelete);
mListener = listener;
ROWDetailHotTrendingNewsContainer.setOnClickListener(this);
TVMessageEdit.setOnClickListener(this);
IMGMessageDelete.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ROW_DetailHotTrendingNewsContainer:
mListener.onRowDetailHotTrendingNewsContainerClick(ROWDetailHotTrendingNewsContainer, getAdapterPosition());
break;
case R.id.TV_MessageEdit:
mListener.onRowMessageEditClick(TVMessageEdit, getAdapterPosition());
break;
case R.id.IMG_MessageDelete:
mListener.onRowMessageDeleteClick(IMGMessageDelete, getAdapterPosition());
break;
default:
break;
}
}
}
public interface RecyclerViewClickListener {
void onRowDetailHotTrendingNewsContainerClick(View view, int position);
void onRowMessageEditClick(View view, int position);
void onRowMessageDeleteClick(View view, int position);
}
}
Это ModelComment.java
public class ModelDetailHotTrendingNewsComment {
private String idcontent;
private String messageimage;
private String messageusername;
private String messagedescription;
private String messagedate;
private int messageisedit;
private String messageedittime;
private String messageedit;
private String messagedelete;
public ModelDetailHotTrendingNewsComment(String idcontent, String messagedescription, String messagedate, int messageisedit, String messageedittime) {
this.idcontent = idcontent;
this.messagedescription = messagedescription;
this.messagedate = messagedate;
this.messageisedit = messageisedit;
this.messageedittime = messageedittime;
}
public String getIdcontent() {
return idcontent;
}
public void setIdcontent(String idcontent) {
this.idcontent = idcontent;
}
public String getMessageimage() {
return messageimage;
}
public void setMessageimage(String messageimage) {
this.messageimage = messageimage;
}
public String getMessageusername() {
return messageusername;
}
public void setMessageusername(String messageusername) {
this.messageusername = messageusername;
}
public String getMessagedescription() {
return messagedescription;
}
public void setMessagedescription(String messagedescription) {
this.messagedescription = messagedescription;
}
public String getMessagedate() {
return messagedate;
}
public void setMessagedate(String messagedate) {
this.messagedate = messagedate;
}
public String getMessageedittime() {
return messageedittime;
}
public void setMessageedittime(String messageedittime) {
this.messageedittime = messageedittime;
}
public String getMessageedit() {
return messageedit;
}
public void setMessageedit(String messageedit) {
this.messageedit = messageedit;
}
public String getMessagedelete() {
return messagedelete;
}
public void setMessagedelete(String messagedelete) {
this.messagedelete = messagedelete;
}
}