I'm an iOS developer new to Android. I'm creating my first Android app and I have several questions. My app uses Android Studio, gradle, and it's based on Parse (the backend). Basically, takes messages from the backend and shows them. User has the possibility to delete them, or click them and see the detail, and of course unread messages have a different color.This is the code of one class, called MessagesListFragment.java, after that a few questions.package com.ricardoruizlopez.xxxxx.messages;import ...public class MessagesListFragment extends Fragment  {private static final String LOG_TAG = MessagesListFragment;MessagesAdapter mAdapter;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    View v = inflater.inflate(R.layout.messages_list_layout, container, false);    final ListView listView = (ListView) v.findViewById(R.id.list);    // load messages and attach them to the list    ParseQuery<Message> messagesQuery= ParseQuery.getQuery(Message.class);    messagesQuery.whereEqualTo(receiver, ParseUser.getCurrentUser());    messagesQuery.whereEqualTo(deleted, false);    messagesQuery.include(sender);    messagesQuery.orderByDescending(createdAt);    messagesQuery.setLimit(1000);    final ProgressDialog progress = ProgressDialog.show(getActivity(), null, getString(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_LOADING_MESSAGES));    messagesQuery.findInBackground(new FindCallback<Message>() {        @Override        public void done(List<Message> list, ParseException e) {            progress.dismiss();            if (e == null) {                mAdapter = new MessagesAdapter(list);                listView.setAdapter(mAdapter);            } else {                Log.d(LOG_TAG, Error loading messages.  + e.getLocalizedMessage());                new AlertDialog.Builder(getActivity())                        .setTitle(R.string.ALERT_VIEW_ERROR)                        .setMessage(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_ERROR_LOADING_MESSAGES)                        .setPositiveButton(R.string.ALERT_VIEW_OK, null)                        .show();            }        }    });    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {        @Override        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {            Log.d(LOG_TAG, onItemClick);            Message message = (Message)mAdapter.getItem(position);            // mark message as read if needed            if (message.getUnread()) {                message.setUnread(false);                mAdapter.notifyDataSetChanged();                message.saveInBackground();            }            // show message detail            Intent messageDetail = new Intent(getActivity(), MessageDetailActivity.class);            MessageDetailActivity.message = message;            startActivity(messageDetail);        }    });    return v;}@Overridepublic void onViewCreated(View view, Bundle savedInstanceState) {    super.onViewCreated(view, savedInstanceState);    //requestMessages();}class MessagesAdapter extends BaseAdapter {    private final List<Message> mMessages;    public MessagesAdapter(List<Message> messages) {        mMessages=messages;    }    @Override    public int getCount() {        return mMessages.size();    }    @Override    public Object getItem(int position) {        return mMessages.get(position);    }    @Override    public long getItemId(int position) {        return 0;    }    @Override    public View getView(final int position, View convertView, ViewGroup parent) {        if (convertView == null) {            convertView = View.inflate(getActivity(), R.layout.message_item, null);        }        Message message=mMessages.get(position);        CustomTextView senderTextView = (CustomTextView) convertView.findViewById(R.id.senderTextView);        senderTextView.setText(getString(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_MESSAGE_FROM, message.getSender().getString(displayName)));        CustomTextView dateTextView = (CustomTextView) convertView.findViewById(R.id.dateTextView);        Date createdAt = mMessages.get(position).getCreatedAt();        DateFormat df=DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);        dateTextView.setText(df.format(createdAt));        Button deleteButton = (Button) convertView.findViewById(R.id.deleteButton);        deleteButton.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                new AlertDialog.Builder(getActivity())                        .setTitle(R.string.ALERT_VIEW_WARNING)                        .setMessage(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_MESSAGE_DELETION_CONFIRMATION)                        .setPositiveButton(R.string.ALERT_VIEW_YES, new DialogInterface.OnClickListener() {                            public void onClick(DialogInterface dialog, int id) {                                deleteMessage(position);                            }                        })                        .setNegativeButton(R.string.ALERT_VIEW_NO, null)                        .show();            }        });        // set colors accoring if it's read or not        CustomTextView fromTextView = (CustomTextView) convertView.findViewById(R.id.fromTextView);        if (message.getUnread()) {            senderTextView.setTextColor(getResources().getColor(R.color.messages_subjectHighligt));            dateTextView.setTextColor(getResources().getColor(R.color.messages_unread));            fromTextView.setTextColor(getResources().getColor(R.color.messages_unread));        } else {            senderTextView.setTextColor(getResources().getColor(R.color.messages_read));            dateTextView.setTextColor(getResources().getColor(R.color.messages_read));            fromTextView.setTextColor(getResources().getColor(R.color.messages_read));        }        return convertView;    }    private void deleteMessage(final int position) {        Message message = mMessages.get(position);        message.setDeleted(true);        final ProgressDialog progress = ProgressDialog.show(getActivity(), null, getString(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_DELETING_MESSAGE));        message.saveInBackground(new SaveCallback() {            @Override            public void done(ParseException e) {                progress.dismiss();                if (e == null) {                    mMessages.remove(position);                    notifyDataSetChanged();                } else {                    Log.d(LOG_TAG, Error deleting message.  + e.getLocalizedMessage());                    new AlertDialog.Builder(getActivity())                            .setTitle(R.string.ALERT_VIEW_ERROR)                            .setMessage(R.string.MESSAGES_TABLE_VIEW_CONTROLLER_ERROR_DELETING_MESSAGE)                            .setPositiveButton(R.string.ALERT_VIEW_OK, null)                            .show();                }            }        });    }}}After reading my code I would like to know any suggestion to improve my android skills. Some questions I have:Should I configure item's click after done? Just after I create the adapter. If I do that, I think mAdapter could be a local variable rather than an instance variable. And I guess that's better.Why is setOnItemClickListener working if in that moment the adapter is null?Is it normal to put the deletion logic (even the confirmation dialog) inside the adapter?Is it normal to configure the adapter when I receive the data from network? And setup with the ListView in that moment?Is the adapter like a ViewController form iOS?
Using an Adapter with Parse query in Android
java;android;parse.com