Hi guys.
After the help of Mark, which i am using the code he wrote me to get the items from a column as Array list.
Thanks again
Sorry if some of my questions look a bit stupid - i am learning as i go…
I set an adapter to the list view and indeed its presenting the strings from the table columns as list items. But…
now comes the interesting part -
When i entered the strings to the column (first is the top one and so on…) the result was like so:
“Room”, “House”, “Apartment”, “Any type”. Any type was the one that was entered first, so its the bottom one now.
The result that i want is the opposite - “Any type” first and so on… I changes it in the table and saved it. Didnt help.
I guess of course there is a “sortBy” when fetching the results - didnt understand how to it with query options.
I will put the code after so please advice me how to do it.
Now comes the bigger problem - i managed to pass the clicked item value by intent to a TextView in the Fragment
that opens the DialogFragment, where the ListView is being showed. But…
The wrong value is being passed, which i dont understand why… Actually, its being passed in the order that i wanted
from the beginning !! Meaning - i will try to be more clear… When i open the DialogFragment, thats what i see:
Room
House
Apartment
Any type
When i click “Room”, the value that is being passed to the other Fragment is “Any type”.
When i click “House”, the value that is being passed to the other Fragment is “Apartment”.
And! When i click “Any type”, which is last on the list, the app is crashing!
Whats going on there?? !!
Her is the Dialog fragment code:
final ArrayList<String> propertyTypes = new ArrayList<String>();
final ArrayList<Integer> numOfRoomies = new ArrayList<Integer>();
Backendless.Data.of(DialogOptions.class).find(new AsyncCallback<BackendlessCollection<DialogOptions>>() {
@Override
public void handleResponse(final BackendlessCollection<DialogOptions> dialogOptions) {
final Iterator<DialogOptions> iterator = dialogOptions.getCurrentPage().iterator();
while (iterator.hasNext()) {
DialogOptions dialogOptionsObject = iterator.next();
propertyTypes.add(dialogOptionsObject.getPropertyTypes());
// numOfRoomies.add( dialogOptionsObject.getNumOfRoomies() );
}
adapter = new ArrayAdapter<String>(getActivity(), R.layout.dialog_option_list_item, R.id.presentListItem, propertyTypes);
mylist.setAdapter(adapter);
mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String chosenItem = propertyTypes.get(position);
Intent intent = new Intent();
intent.putExtra("chosenItem", chosenItem);
getTargetFragment().onActivityResult(
getTargetRequestCode(), Activity.RESULT_OK, intent);
dismiss();
}
});
}
@Override
public void handleFault(BackendlessFault fault) {
// TODO: make sure to log the exception, just in case
}
});
Here is code in the other fragment that is getting the intent:
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
final LinearLayout propertTypes = (LinearLayout)view.findViewById(R.id.propertyTypes);
propertTypes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showDialog(getActivity(), "OptionDialog");
}
});
}
private void showDialog(FragmentActivity activity, String optionDialog) {
android.support.v4.app.FragmentManager manager = getFragmentManager();
DialogFragment dialog = new OptionDialogFragment();
dialog.setTargetFragment(this, 0);
dialog.show(manager, "OptionDialog");
dialog.setCancelable(true);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 0:
if (resultCode == Activity.RESULT_OK) {
if(data!=null){
// set value to your TextView
chosenProperty.setText(data.getStringExtra("chosenItem"));
}
}
break;
}
}
Thanks a lot in advanced for any help!!