0

I am working on an activity with a list view supported by fragment activity. The fragment is inflated with the data received from the Parse Framework on Back4app

The following is the code for the fragment:-

package com.footzila.footify;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.parse.FindCallback;
import com.parse.GetCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class NewsFragment extends Fragment
{
    //private List<String> mNewsList;
    private ListView lv;
    private List<Events> myEvents;
    public NewsFragment() {
        // Required empty public constructor
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View fragmentView= inflater.inflate(R.layout.fragment_news, container, false);
        lv = (ListView) fragmentView.findViewById(R.id.MyListView);
      //  mNewsList =new ArrayList<String>();
        myEvents = new ArrayList<Events>();

        /**
        mNewsList.add("My first Item");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
        mNewsList.add("Some MoreItem");
**/
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Events");
        //query.whereEqualTo("playerEmail", "dstemkoski@example.com");
        query.findInBackground(new FindCallback<ParseObject>(){
            public void done(List<ParseObject> obj, ParseException e)
            {
                if(e == null)
                {
                    Log.d("score", "Retrieved the object." +obj.size());
                    for(ParseObject parseObject : obj )
                    {
                        String title = (String)parseObject.get("Title");
                        String link = (String)parseObject.get("Link");
                        String imgLink = (String)parseObject.get("Imlink");
                        Events ev =new Events(title,imgLink,link);
                        myEvents.add(ev);
                        myEvents.add(new Events("ABC", "https://qph.ec.quoracdn.net/main-thumb-62579190-50-tdsgvwmqywsdhbkoosmzkhrumpkzcxxq.jpeg","www.google.com"));
                    }
                    lv.setAdapter(new MyAdapter());
                }
                else  {
                    Log.d("score", "The getFirst request failed.");
                }
            }
        });


        return fragmentView;
    }

    private class MyAdapter extends BaseAdapter
    {
        @Override
        public int getCount() {
            return myEvents.size();
        }

        @Override
        public Object getItem(int i) {
            return myEvents.get(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup)
        {
            View rV=getActivity().getLayoutInflater().inflate(R.layout.row,null);
            Events rowEvent = myEvents.get(i);
            TextView tv = (TextView) rV.findViewById(R.id.textView);
            tv.setText(rowEvent.getTitle());
            ImageView iv= (ImageView)rV.findViewById(R.id.imageView2);
            Picasso.with(getActivity()).load(rowEvent.getImgLink()).into(iv);//"http://i.imgur.com/DvpvklR.png"
            return rV;
        }
    }
}

In the Parse Framework there is a class name "Events " with 3 strings Title, ImLink, Link

The MainActivity having the Fragment Layout has the following code

package com.footzila.footify;

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.parse.Parse;

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        Parse.initialize(this,"pQMefFCLGJ2PejA3dJO3EaEil3AD63SNRbSNGW9m","KkJDsaNKR8tOHkjRLp6ISCV67xF1pMAWQzyVicSI"); //App id and client key
        setContentView(R.layout.activity_main);

    }
}
Yash Gupta
  • 331
  • 2
  • 8

1 Answers1

0

I'm afraid the "Parse.initialize" section of your MainActivity code might not be complete. Note that you'll need to point the server URL to the host (on this case, Back4App's URL) and actually trigger the "build()".

I'd suggest you to alter that specific part to something like this:

Parse.initialize(new Parse.Configuration.Builder(this)
                .applicationId("YOUR_APP_ID")
                .clientKey("YOUR_CLIENT_KEY")
                .server("https://parseapi.back4app.com/").build()
);

I think that might do the trick for the query to give proper results.

Casagrande
  • 90
  • 7