2

I have this strings array just with the purpose of testing a list view

  <string-array name="prueba">

        <item> calculo </item>
        <item> fisica </item>
        <item>logica</item>
        <item>programacion</item>
        <item> adsad</item>
        <item>asdasdasdsad</item>
        <item> trtr </item>
        <item> yuuyu </item>
        <item>ngngn</item>
        <item>dgdg</item>
        <item> liuj</item>
        <item>kmbbm</item>

    </string-array>

this is the listView code

public class Grades extends ListFragment implements AdapterView.OnItemClickListener {    

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.grades_fragment,container,false);    
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ArrayAdapter adapter = ArrayAdapter.createFromResource(getActivity(), R.array.prueba, android.R.layout.simple_list_item_1);
        setListAdapter(adapter);
        getListView().setOnItemClickListener(this);
    }    

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {    

        Toast.makeText(getActivity(),"item" + position , Toast.LENGTH_SHORT).show();

    }
}

So what I want is to instead of using that "test" array, using some strings that are located on my Parse.com Data, adding elements to the array when a string is added to the Data base in Parse.com

How can I do that?

Sebastian Delgado
  • 706
  • 3
  • 7
  • 26

2 Answers2

0

You need to fetch the strings from the object by the same name through which you saved. Say for example it is listStrings.

ParseQuery<ParseObject> myObject= ParseQuery.getQuery("listStrings");

After that just call this function

myObject.fetchInBackground(new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
   if (e == null) {
     // Assign the values here and use it accordingly
   } else {
     // Failure!
  }
}
});

You can also use the following function:

fetchAllInBackground(List<T> objects)
Najeebullah Shah
  • 4,164
  • 4
  • 35
  • 49
0

There is some info on how to retrieve data from parse.com here -> android_guide#objects Using a ParseQuery, you can obtain the ParseObject. You can then query this object for details and add this to your listview.

code snippets from link above.

To get the object.

ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
query.getInBackground("xWMyZ4YEGZ", new GetCallback<ParseObject>() {
  public void done(ParseObject object, ParseException e) {
    if (e == null) {
      // object will be your game score
    } else {
      // something went wrong
    }
  }
});

To query the object:

int score = gameScore.getInt("score");
String playerName = gameScore.getString("playerName");
boolean cheatMode = gameScore.getBoolean("cheatMode");

They have "getX" methods for all data types.

To add this to your listview. using arrayadapter

void add(T object)

Adds the specified object at the end of the array.

void addAll(Collection collection)

Adds the specified Collection at the end of the array.

void addAll(T... items)

Adds the specified items at the end of the array.

This post here shows how to use this.

Community
  • 1
  • 1