Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8676273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:09:11+00:00 2026-06-12T20:09:11+00:00

I have an application it have two activities. When press a button in the

  • 0

I have an application it have two activities. When press a button in the main activity, it shows customized listview, then I press hard back button and go to the main page of my application.

Then I again press the same button and go to the listview it shows the repeated values in the listview.

Any one have any sloution please???

        CookList = new ArrayList<HashMap<String, String>>();
    try {
        url = new URI(cookUri);
        List<DataModels> list1 = new ArrayList<DataModels>();
        CookListServer cookServer = new CookListServer();
        StringBuilder responseString =  cookServer.CookConnect(url, "hi");
        System.out.println("responseString---------"+responseString);

        for(int i=0; i< itemId.size(); i++){
            HashMap<String, String> Cook = new HashMap<String, String>();

            Cook.put("ItemId", itemId.get(i));
            System.out.println("itemId--------"+itemId.get(i));
            Cook.put("ItemName", itemName.get(i));
            Cook.put("ItemQty", itemQty.get(i));
            CookList.add(Cook);
            list1.add(get(i));
        }
        adapter = new MySimpleArrayAdapter(context, CookList, R.layout.cooklist_item, list1);
        setListAdapter(adapter);

    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
 }

private DataModels get(int s) {
    return new DataModels(s);
}

@Override
public void onResume() {
    super.onResume();
    adapter.notifyDataSetChanged();
}

@Override
protected void onDestroy() {
    super.onDestroy();
}



// Adapter to list the Albums
public class MySimpleArrayAdapter extends ArrayAdapter<HashMap<String, String>> implements SectionIndexer {
    private final Context context;
    private final ArrayList<HashMap<String, String>> values;
    List<DataModels> modellist;

    public MySimpleArrayAdapter(Context context, ArrayList<HashMap<String, String>> values, int layout, List<DataModels> modellist) {
        super(context, R.layout.cooklist_item, values);
        this.context = context;
        this.values = values;
        this.modellist = modellist;
    }

    private final class ViewHolder {
        public TextView Nametext;
        public TextView Qntytext;
        public Button prepareButton;
    }

    private LayoutInflater mLayoutInflater = null;
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            if (mLayoutInflater == null) {
                mLayoutInflater = LayoutInflater.from(context);
            }

            convertView = mLayoutInflater.inflate(R.layout.cooklist_item, null);

            viewHolder = new ViewHolder();
            viewHolder.Nametext = (TextView) convertView.findViewById(R.id.label);
            viewHolder.Qntytext = (TextView) convertView.findViewById(R.id.textView1);
            viewHolder.prepareButton = (Button) convertView.findViewById(R.id.prepareButton1);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
            ((ViewHolder) convertView.getTag()).prepareButton.setTag(modellist.get(position));
        }

        final HashMap<String, String> cooklist = values.get(position);
        final ViewHolder holder = (ViewHolder) convertView.getTag();

        final String ItemId = cooklist.get("ItemId");
        final String ItemName = cooklist.get("ItemName");
        final String ItemQty = cooklist.get("ItemQty");

        System.out.println("ItemId---------"+ItemId);
        System.out.println("ItemName---------"+ItemName);
        System.out.println("ItemQty---------"+ItemQty);

        holder.Nametext.setText(ItemName);

        holder.Qntytext.setText(ItemQty);

        registerForContextMenu(convertView);


        holder.prepareButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                DataModels element = (DataModels) viewHolder.prepareButton.getTag();
                holder.prepareButton.setEnabled(false);
            }
        });
        return convertView;
    }

    @Override
    public int getPositionForSection(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getSectionForPosition(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Object[] getSections() {
        // TODO Auto-generated method stub
        return null;
    }


}

Thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:09:12+00:00Added an answer on June 12, 2026 at 8:09 pm

    I got a solution

    @Override
    protected void onDestroy() {
        itemId.clear();
        itemName.clear();
        itemQty.clear();
        super.onDestroy();
    }
    

    Thanks….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application is having two activities. In first activity, I have one button and
I have an application that contains two Activities with <intent-filter> <action android:name=android.intent.action.MAIN/> <category android:name=android.intent.category.LAUNCHER/>
I have two activities, one is main and I have another activity called Test
suppose that you have two activities A(which is the main activity) and B when
In my application I have two activities. In the first activity I have a
I have an Android application that contains two Activities . Activity A has a
I have two activities in an android application, each has a button that goes
I have two activities in my Android 2.1 application. The first is the Main
Im making a multi activity application and the first two activities i made have
I have two activities: A: a Splash Screen B: the Main activity When the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.