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

  • SEARCH
  • Home
  • 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 8894489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:30:37+00:00 2026-06-14T23:30:37+00:00

listview keeps getting doubled (populated everytime with previous data making the data appear twice)

  • 0

listview keeps getting doubled (populated everytime with previous data making the data appear twice) everytime the activity is loaded

public class FragmentActivity extends Activity implements OnItemClickListener{

    private ListView discrepancy_list;
    private DiscrepancyListAdapter list_adapter = null;
    private ArrayList<CommonEntity> discrepancyList = new ArrayList<CommonEntity>();
    private RelativeLayout objRelativeLayout;
    private static int X_CO_ordinate;
    private static int Y_CO_ordinate;
    private ArrayList<String> arrlstCo_ordinate;
    private ArrayList<String> arrlst_Count;
    private boolean touch = true,isOnLaunch = false;
    private int editText_ID=1,count=1;
    private EditText objEditText;
    private SortedMap<Integer,String> mapDefect=null;
    private int final_position; 
    private ImageButton objImageButton;
    private DatabaseHandler db;
    Bitmap StoredBitmap;
    Drawable StoredDrawable;
    private static int dataSet = 0;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState){

         super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapDefect=new TreeMap<Integer, String>();
        arrlstCo_ordinate=new ArrayList<String>();
        arrlst_Count=new ArrayList<String>();
        discrepancy_list = (ListView)findViewById(R.id.number_list);
        discrepancy_list.setOnItemClickListener(this);
        db = new DatabaseHandler(this);

        objRelativeLayout=(RelativeLayout) findViewById(R.id.RelativeLayout);
        objRelativeLayout.setOnTouchListener(new View.OnTouchListener(){
            public boolean onTouch(View v, MotionEvent event){
                String strEditText;
                if(!checkForDataSaved()){
                if(touch){
                    Log.d("ON", "onTouch called");
                    X_CO_ordinate=(int) event.getX() ; 
                    Y_CO_ordinate=(int) event.getY();

                    boolean isNotDuplicate=checkDuplicateElement(X_CO_ordinate,Y_CO_ordinate);
                    if(isNotDuplicate){
                        Log.d("TOUCH", "TOUCH"+X_CO_ordinate+"|"+Y_CO_ordinate+"|"+"Touch :");
                        if(objEditText != null){
                            strEditText=objEditText.getText().toString();
                            Log.d("Err", "EditText not null"+strEditText);

                            if(strEditText != null && strEditText.length() != 0){
//                              if(chekMapEntry(objEditText.getId(), objEditText.getText().toString(), ""+X_CO_ordinate+"|"+Y_CO_ordinate))
//                              {
                                arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
                                arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
                                mapDefect.put(objEditText.getId(),objEditText.getText().toString());
                                Log.d("Err", "In Touch Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
                                objEditText.setVisibility(View.INVISIBLE);
                                //}else{Toast.makeText(FragmentActivity.this, "Duplicate map entry", Toast.LENGTH_LONG).show();}
                                addEditText();
                                Log.d("Err", "String not null");
                            }else{
                                Log.d("Err", "String null");
                                Toast.makeText(FragmentActivity.this, "Please log the defect ::: in onTouch()", Toast.LENGTH_LONG).show();
                            }
                        }else{
                            Log.d("Err", "EditText  null");
                            arrlst_Count.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
                            arrlstCo_ordinate.add(""+X_CO_ordinate+"|"+Y_CO_ordinate);
                            Log.d("Err", "In Touch else Map Size :"+mapDefect.size() +"Arr List Size :"+arrlstCo_ordinate.size());
                            Drawable relative_image_bg = objRelativeLayout.getBackground();
                            Bitmap bitmap = ((BitmapDrawable)relative_image_bg).getBitmap();
                            Bitmap bitmap2 = ((BitmapDrawable)(getResources().getDrawable(R.drawable.no_image_screen_new))).getBitmap();

                            if(bitmap.sameAs(bitmap2)){
                                Toast.makeText(FragmentActivity.this, "Please capture the image", Toast.LENGTH_LONG).show();
                            }else{
                                Toast.makeText(FragmentActivity.this, "Not equal..", Toast.LENGTH_LONG).show();
                                addEditText();
                            }
                        }
                    }
                    touch=false;
                }else{
                    touch=true;
                }
            }
                return true;
            }

            private boolean checkDuplicateElement(int x_CO_ordinate,int y_CO_ordinate){
                String strX=String.valueOf(x_CO_ordinate);
                String strY=String.valueOf(y_CO_ordinate);

                for(int i=0;i<arrlstCo_ordinate.size();i++){
                    String strResult=arrlstCo_ordinate.get(i);
                    String []arrResult=StringUtils.split(strResult, "|");
                    String strTemp_X=arrResult[0];
                    String strTemp_Y=arrResult[1];
                    Log.d("CO", ""+strTemp_X+strTemp_Y+"|"+strX+strY);

                    if(strTemp_X.equalsIgnoreCase(strX) || strTemp_Y.equalsIgnoreCase(strY)){
                        Log.d("DUP", "Duplicate element is not allow");
                        Toast.makeText(FragmentActivity.this, "Duplicate element is not allow", Toast.LENGTH_SHORT).show();
                        return false;
                    }
                }
                return true;
            }
        });

        //add list in main.xml

        addList();
        getDefects();


    }

    private void addList(){


        discrepancyList = LocalDatabaseOperations.callDBToGetList(this);

        list_adapter = new DiscrepancyListAdapter(this, discrepancyList);
        discrepancy_list.setAdapter(list_adapter);
        isOnLaunch = true;
        discrepancy_list.performItemClick(null, 0, discrepancy_list.getFirstVisiblePosition());


    }

    private void getDefects(){

        if(LocalDatabaseOperations.callDBToGetDefects(this) == true){
            fechCoordinate();
            addViewEditText();

        }
    }

So this is the activity that loads a “list of discrepancies” on the LHS and information about the first item in the list on the RHS of the fragment. But when I go back and come back to this screen, the same acitivty is loaded making it to load the activity. This should happen. However the previous data is also present making the entire data to double.

  • 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-14T23:30:38+00:00Added an answer on June 14, 2026 at 11:30 pm

    In your callDBToGetList() function, I am assuming that you are returning a list(say myList). Make this line as first line of your callDBToGetList() function.

    myList.clear();
    

    Replace myList with the name of list that you are returning.

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

Sidebar

Related Questions

ListView listView; Activity activity; public ArrayList<Tasks> tasks; View v; public TaskAdapter(Activity activity, ArrayList<Tasks> tasks)
I have dynamic listview on my android client app that receive data from remote
Im trying to display this listview, but I keep getting a: 07-17 21:14:22.233: ERROR/AndroidRuntime(349):
my ListView seems to be working correctly when the images loaded can be viewed
I have an android-app with a listview in an activity. The listview has, if
I have a case that keeps coming up where I'm using a ListView or
I got 2 classes in my project. The first class(main) have a listview and
I have an issue where my ListView (when showing as a string variable) keeps
I have written some code to set data to listview from a webpage. I
I keep getting this error in my Main.Activity.java. The Method i(String, String) is undefined

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.