简体   繁体   中英

Maps intent inside of a arraylist

I'm creating an app that's a tourguide of a city. I have categories like food, attractions etc. inside each category I made a list view with a custom array adapter. inside the array list holds images, description of each place and a address. I'm trying to set a onclick listener for the address part and when clicked it will pull up maps with the location. this is my code so far. I'm getting an error with the Override onClick saying "method does not override method from it's superclass."

'public class DinnerFragment extends Fragment {

public DinnerFragment() {
    // Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.list_view, container, false);

    final TextView address = (TextView) rootView.findViewById(R.id.address);
    //Create a list for locations
    ArrayList<List> locations = new ArrayList<List>();

    locations.add(new List("Coconuts", "Chill, beachy hangout on the Intracoastal dishing seafood & Sunday brunch while yachts cruise by.", "429 Seabreeze Blvd, Fort Lauderdale, FL 33316" , R.drawable.coconuts));
    locations.add(new List("Trulucks","Upscale seafood & steak chain featuring half-price happy hours, a deep wine list & swanky surrounds", "2584A E Sunrise Blvd, Fort Lauderdale, FL 33304", R.drawable.trulucks ));
    locations.add(new List("Pirate Republic", "Lively riverfront spot with a Caribbean-Mediterranean menu, live music & weeknight happy hour.", "400 SW 3rd Ave, Fort Lauderdale, FL 33315", R.drawable.pirate_republic ));
    locations.add(new List("15th Street Fisheries", "Veteran marina eatery dishing upscale & casual fare with live music & tarpon feeding from the dock.", "1900 SE 15th St, Fort Lauderdale, FL 33316", R.drawable.fifthteenthst_fisheries));
    locations.add(new List("Shooters Waterfront","Laid-back spot on the Intracoastal Waterway offering food, drinks, live music & water views.","3033 NE 32nd Ave, Fort Lauderdale, FL 33308",R.drawable.shooterswaterfront ));
    locations.add(new List("OCEAN2000", "Ocean views from the veranda & menu of American dishes with Latin flair are highlights at this spot.", "2000 N Ocean Blvd, Fort Lauderdale, FL 33305", R.drawable.oceans2000));
    locations.add(new List("Blue Moon Fish Co.","Foodies flock to this upmarket fish house with a romantic vibe, outdoor deck & Sunday buffet brunch.","4405 W E Tradewinds Ave, Lauderdale-By-The-Sea, FL 33308",R.drawable.bluemoonfish));
    locations.add(new List("Two Georges","Lively, multiroomed dockside spot offering seafood, cocktails, live music & Intracoastal views.","1754 SE 3rd Ct, Deerfield Beach, FL 33441",R.drawable.twogeorges));
    locations.add(new List("The Whale's Rib","Seafood & \"whale\" fries are hot items at this bustling beach cafe/bar with old-time Florida flavor. Was featured on the Food Network","2031 NE 2nd St, Deerfield Beach, FL 33441",R.drawable.whalesrib));
    locations.add(new List("Ruth's Chris Steak House", "Outpost of upmarket steakhouse chain known for sizzling, butter-topped beef in an elegant setting", "2525 N Federal Hwy, Fort Lauderdale, FL 33305" ,R.drawable.ruthschrissteak));
    locations.add(new List("The Capital Grille", "Outpost of the upscale steakhouse chain offers classic American fare & a clubby, refined setting.", "2430 E Sunrise Blvd, Fort Lauderdale, FL 33304", R.drawable.capitalgrille ));
    locations.add(new List("Chima Steakhouse", "Posh, stylish venue for meats carved tableside, ample salad bar, outdoor bar & weeknight happy hour.", "2400 E Las Olas Blvd, Fort Lauderdale, FL 33301", R.drawable.chimasteak));
    locations.add(new List("Morton's The Steakhouse", "Upscale chain for aged prime beef, seafood & other traditional steakhouse fare in a clubby space.", "500 E W Broward Blvd #127, Fort Lauderdale, FL 33394" ,R.drawable.mortonssteak));
    locations.add(new List("Pampa Gaucho Steakhouse","Known as the best Brazilian Steakhouse in all of South Florida", "4490 N Federal Hwy, Lighthouse Point, FL 33064", R.drawable.truluckssteak ));
    // Create a ArrayAdapter from the made ListAdapter (custom ArrayAdapter) The adapter will set to display the
    // contents of the locations list
    ListAdapter adapter =
            new ListAdapter(getActivity(), locations);

    // Find the ListView object (in xml list_view) named list.
    ListView listView = (ListView) rootView.findViewById(R.id.list);

    //Make the ListView use the ArrayAdapter(adapter) we created above, so the
    //ListView will display list items for each location in the list of locations.
    listView.setAdapter(adapter);


    address.setOnClickListener(new Intent() {

        @Override
        public void onClick(View v) {
            Intent geoIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(("geo:0,0?q=" + address.getText().toString())));
            startActivity(geoIntent);
        }
    });


    return rootView;
}

`

Intent does not have a function called onClick. You will probably want to pass a different Object to setOnClickListener. You should try an OnClickListener of the View Package

Intent does not have a function called onClick. You will probably want to pass a different Object to setOnClickListener.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM