Yariv BE February 2016

Wrong ListView item is passed by the intent

I am using BackendLess backend service, but my prob is (i guess) more to android/java. So even if u are not familiar with BackendLess, i guess u can help, if u know of course :)

I have there a Fragment that calls and opens a DialogFragment with a ListView. Using there an iterator to retrieve the data. It brings each column from the data table as an Array. I set an onClickedItemListener that when item is clicked, it send the value to a TextView in the Fragment it was called from.

The data comes in the wrong order - didnt get how to do a sortBy, that connects to the bigger prob i have there - There is a column there named "PropertyTypes". It holds 4 strings, which are coming out in the opposite order that i need. I want the "A" first, and get: "D" "C" "B" "A" ok, so far no big deal, i guess can be sorted out with a sortBy that i just dont know how to do. But... what happens is that it sends the wrong value to the TextView, meaning, for example, when i press "C" it set "A" on the TextView and so on, and, when i press the last one, in this case "A", the app is crashing...

What the hell is going on there?? :))

Here is the code - The DialogFragment code:

public class OptionDialogFragment extends DialogFragment implements
        AdapterView.OnItemClickListener {

    ListView mylist;
    TextView chosenProperty;
    TextView presentListItem;
    ArrayAdapter adapter;

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    //mylist.addHeaderView(inflater.inflate(R.layout.option_dialog_header, null, false));
    View view = inflater.inflate(R.layout.option_dialog_content, null, false);
    mylist = (ListView) view.findViewById(R.id.list);
    View headerView = inflater.inflate(R.layout.option_dialog_header, mylist, false);
    headerView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick        

Answers


Nidhin Prathap February 2016

Reference :- https://backendless.com/feature-47-loading-data-objects-from-server-with-sorting/

To Sort while retrieving Object use :-

QueryOptions queryOptions = new QueryOptions(); queryOptions.addSortByOption( "created ASC" ); dataQuery.setQueryOptions( queryOptions );

Use Query as below:-

// fetch restaurants


Backendless.Data.of( Restaurant.class ).find( dataQuery, new AsyncCallback<BackendlessCollection<Restaurant>>(){

Post Status

Asked in February 2016
Viewed 1,675 times
Voted 7
Answered 1 times

Search




Leave an answer