Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Toast Messages Appearing Twice In My BaseAdapter

I have a problem with my toast messages appearing twice when I test my app. I tested in my logcat and my getView() and getCount() methods are being called twice producing two toast messages. I only want my toast message to appear once. My question is, how would I stop or remove the view after one toast message? Assuming that's the answer to my problem?

    public class GetTheDealerListViewAdapter extends BaseAdapter {

    private JSONArray dataArray;
    private Activity activity;
    private static LayoutInflater inflater = null; 

    GetTheDealerListViewAdapter(JSONArray jsonArray, Activity a){
        this.dataArray = jsonArray;
        this.activity = a;
        inflater = (LayoutInflater) this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // this.dataArray.remove(dataArray.length());
        return this.dataArray.length();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        allTheDealershipInfo infoHolder;

        if(convertView == null){
            convertView = inflater.inflate(R.layout.show_dealership_information, parent, false);

            infoHolder = new allTheDealershipInfo();
            infoHolder.dealerships = (TextView) convertView.findViewById(R.id.nameOfDealership);
            infoHolder.state = (TextView) convertView.findViewById(R.id.theState);
            infoHolder.city = (TextView) convertView.findViewById(R.id.theCity);
            infoHolder.phone = (TextView) convertView.findViewById(R.id.thePhone);
            infoHolder.address = (TextView) convertView.findViewById(R.id.theAddress);
            infoHolder.zip = (TextView) convertView.findViewById(R.id.theZip);
            infoHolder.email = (TextView) convertView.findViewById(R.id.theEmail);
            infoHolder.website = (TextView) convertView.findViewById(R.id.theWebsite);
            infoHolder.facebook = (TextView) convertView.findViewById(R.id.theFacebook);
            infoHolder.twitter = (TextView) convertView.findViewById(R.id.theTwitter);  
            infoHolder.youtube = (TextView) convertView.findViewById(R.id.theYoutube);
            infoHolder.googlePlus = (TextView) convertView.findViewById(R.id.theGoogle_plus);
            infoHolder.yelp = (TextView) convertView.findViewById(R.id.theYelp);
            convertView.setTag(infoHolder);

        } else {
            infoHolder = (allTheDealershipInfo) convertView.getTag();
        }

        try {
            JSONObject jsonObject = this.dataArray.getJSONObject(position);

            infoHolder.dealerships.setText(jsonObject.getString("dealership")); 
            infoHolder.state.setText(jsonObject.getString("state"));
            infoHolder.city.setText(jsonObject.getString("city"));
            infoHolder.phone.setText(jsonObject.getString("phone"));
            infoHolder.address.setText(jsonObject.getString("address"));
            infoHolder.zip.setText(jsonObject.getString("zip"));
            infoHolder.email.setText(jsonObject.getString("email"));
            infoHolder.website.setText(jsonObject.getString("website"));

            infoHolder.facebook.setText(jsonObject.getString("facebook"));
            infoHolder.twitter.setText(jsonObject.getString("twitter"));
            infoHolder.youtube.setText(jsonObject.getString("youtube"));
            infoHolder.googlePlus.setText(jsonObject.getString("google_plus"));
            infoHolder.yelp.setText(jsonObject.getString("yelp"));


            Toast.makeText(activity, "Call " + jsonObject.getString("dealership"), Toast.LENGTH_SHORT).show();
            Toast.makeText(activity, "Tell " 
            + jsonObject.getString("dealership") 
            + " You Saw Them Using The MyWebsite.com App!", 
            Toast.LENGTH_LONG).show();          


        } catch (JSONException e) {
            e.printStackTrace();
        }


        return convertView;
    }
    }

what are you using because you did not specify in your question? First your code is very confusing. You don't have the proper code. FIX THE MISTAKES AND REPOST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!