Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a RealmList to RealmResult?

I am building a Java android app and I am using realm.io for my database. My problem is I have a RealmList and my Custom ListView adapter only accepts RealmResults. Below is the code and more details.

I have an Chat class that has a RealmList, RealmList, userId and a chatId.

public class Chat extends RealmObject{

private RealmList<Friend> participants;
private RealmList<Message> messages;

@PrimaryKey
private String chatId;
private String userId;

...
}

In my activity where I am trying to display all the messages that the chat has, I can call chat.getMessages() to get all the messages for this chat as a RealmList but my ListView adapter below takes a RealmResult because it extends RealmBaseAdapter

public class MessageAdapter extends RealmBaseAdapter<Message> implements ListAdapter {

private String TAG = getClass().getSimpleName();

public MessageAdapter(Context context,
                   RealmResults<Message> realmResults,
                   boolean automaticUpdate) {
    super(context, realmResults, automaticUpdate);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null)
    {
        convertView = inflater.inflate(R.layout.listitem_message, parent, false);
    }

    Message message = getRealmResults().get(position);

    if (message != null)
    {
        ((TextView) convertView.findViewById(R.id.message_content)).setText(message.getContent());
        DateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.CANADA);
        ((TextView) convertView.findViewById(R.id.message_time)).setText(dateFormat.format(message.getTimestamp()));
    }

    return convertView;
}

public RealmResults<Message> getRealmResults() {
    return realmResults;
}
}

Here is where I call it all

RealmList<Message> messages = chat.getMessages();

    ListView messageList = (ListView) findViewById(R.id.message_list);
    adapter = new MessageAdapter(this, messages, true);
    messageList.setAdapter(adapter);

I am open to changing my RealmList to a RealmResult if possible (I have looked and it doesn't seem to be) or If I can use a RealmList in the custom realm adapter that would another solution. Anything to help me move forward would be great help.

thanks

like image 344
ganlaw Avatar asked Jul 30 '15 21:07

ganlaw


People also ask

How do I change the realmlist in Wow?

Steps 1 Close your current WoW gaming session. The realmlist can only be changed successfully if you’re logged completely out of WoW. 2 Navigate to the WoW folder using File Explorer in Windows or Finder on Mac OS X. ... 3 Open the “Data” folder, then open the “enUS” folder. Mais itens...

How do I open a realmlist file?

If you experience difficulty with locating the realmlist file using File Explorer or Finder, type "realmlist.wtf" into the search bar to navigate directly to this file. Double-click on the "realmlist.wtf" file, and select the option to open the file using Notepad, TextEdit, or any other text-editing program of your choice.

How to convert result to list in realm?

2 Realm has some new features check-in documentation Realm Documentation Realm has copyfromRealm function which we can use to convert the result to list RealmList<Student> student=realm.copyfromRealm(Realmresult); Share Improve this answer Follow

What is a realmlist?

The Realmlist is a special text file in World of Warcraft (WoW) that informs the WoW client which server you need to connect to. Setting, or changing the realmlist is crucial for players who want to play WoW on a private server. The...


1 Answers

Just do

chat.getMessages().where().findAll()

(Answer from here)

like image 64
Grimmy Avatar answered Oct 13 '22 01:10

Grimmy