Android Open Source - FoodFinderApp Display Place Items






From Project

Back to project page FoodFinderApp.

License

The source code is released under:

GNU General Public License

If you think the Android project FoodFinderApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cs499.examples.semesterproject;
//  ww  w.  j av a  2 s.c om
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

public class DisplayPlaceItems extends Activity 
{
  String[] items;
  ArrayList<String> selectedItems = new ArrayList<String>();
  List<NameValuePair> requests;
  ListView lv;
  String url = Constants.URL;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_place_items);
    
    Bundle extras = getIntent().getExtras();
    String sendername = extras.getString("sender");
    String placeName = extras.getString("placeName");
    lv = (ListView) findViewById (R.id.placesItemList);
    
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    pairs.add (new BasicNameValuePair("senderName", sendername));
    pairs.add (new BasicNameValuePair("placeName", placeName));
    pairs.add (new BasicNameValuePair("action", "searchitems"));
    
    requests = new ArrayList<NameValuePair>();
    requests.add (0, new BasicNameValuePair("senderName", sendername));
    requests.add (1, new BasicNameValuePair("placeName", placeName));
    requests.add (2, new BasicNameValuePair("action", "requestitems"));
    
    AsyncSearchItems task = new AsyncSearchItems(DisplayPlaceItems.this, url, pairs, lv);
    task.execute();
    
  }
  
  public void submitItems (View view)
  {
    Log.d("In method: ", "submitItems");
    if (selectedItems.size() > 0)
    {
      String s = "";
      for (int i = 0; i < selectedItems.size(); i++)
      {
        if (i < selectedItems.size()-1)
          s += selectedItems.get(i) + ",";
        else
          s += selectedItems.get(i);
      }
      requests.add(3, new BasicNameValuePair("selectedItems", s));
      Log.d("post for selectedItems: ", s);
      AsyncSendRequest requestTask = new AsyncSendRequest(requests, url, DisplayPlaceItems.this);
      requestTask.execute();
      selectedItems = new ArrayList<String>();
    }
  }
  
  public void notifyDataReceived ()
  {
    //Log.d("Recieved data: ", s);
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener ()
    {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) 
      {
        String s = (String) lv.getItemAtPosition(position);
        String[] itemChars = s.substring(s.indexOf(':')+1, s.length()-1).split(",");
        String itemName = itemChars[0].trim();
        
        if (!alreadyInList(selectedItems, itemName))
        {
          selectedItems.add(itemName);
          Toast.makeText(DisplayPlaceItems.this, itemName + " added to request list ", Toast.LENGTH_LONG).show();
        }
        else
        {
          Toast.makeText(DisplayPlaceItems.this, itemName + " is already in your request list ", Toast.LENGTH_LONG).show();
        }
      }
        
    });
  }
  
  public boolean alreadyInList (ArrayList<String> items, String item)
  {  
    for (int i = 0; i < items.size(); i++)
    {
      if (items.get(i).equals(item))
      {
        return true;
      }
    }
    return false;
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.display_place_items, menu);
    return true;
  }

}




Java Source Code List

cs499.examples.semesterproject.AddItemsActivity.java
cs499.examples.semesterproject.AndroidFoodBankOwnerServlet.java
cs499.examples.semesterproject.AsyncAddItems.java
cs499.examples.semesterproject.AsyncAddPlace.java
cs499.examples.semesterproject.AsyncAddRestaurantToDB.java
cs499.examples.semesterproject.AsyncAuthenticateUser.java
cs499.examples.semesterproject.AsyncSearchAndShowPlaces.java
cs499.examples.semesterproject.AsyncSearchItems.java
cs499.examples.semesterproject.AsyncSendRequest.java
cs499.examples.semesterproject.AsyncViewRequests.java
cs499.examples.semesterproject.Constants.java
cs499.examples.semesterproject.DisplayMap.java
cs499.examples.semesterproject.DisplayMatchingPlaces.java
cs499.examples.semesterproject.DisplayPlaceItems.java
cs499.examples.semesterproject.DisplayPlace.java
cs499.examples.semesterproject.DisplayRequestActivity.java
cs499.examples.semesterproject.FoodBankOwnerActivity.java
cs499.examples.semesterproject.FoodOwnerOptions.java
cs499.examples.semesterproject.LoginActivity.java
cs499.examples.semesterproject.MainActivity.java
cs499.examples.semesterproject.OrganizationOptions.java
cs499.examples.semesterproject.OtherOwnerActivity.java
cs499.examples.semesterproject.QueryActivity.java
cs499.examples.semesterproject.ViewRequests.java
org.json.CDL.java
org.json.CookieList.java
org.json.Cookie.java
org.json.HTTPTokener.java
org.json.HTTP.java
org.json.JSONArray.java
org.json.JSONException.java
org.json.JSONML.java
org.json.JSONObject.java
org.json.JSONString.java
org.json.JSONStringer.java
org.json.JSONTokener.java
org.json.JSONWriter.java
org.json.Kim.java
org.json.Property.java
org.json.XMLTokener.java
org.json.XML.java
org.json.zip.BitInputStream.java
org.json.zip.BitOutputStream.java
org.json.zip.BitReader.java
org.json.zip.BitWriter.java
org.json.zip.Compressor.java
org.json.zip.Decompressor.java
org.json.zip.Huff.java
org.json.zip.JSONzip.java
org.json.zip.Keep.java
org.json.zip.MapKeep.java
org.json.zip.None.java
org.json.zip.PostMortem.java
org.json.zip.TrieKeep.java