The Android display list item is repeated on adding a new item with different data


I am trying working on listactivity in it i am adding items to listview rows . but when i load different data to add an item in list view it repeats the same item added before .

here is my baseadapter class:

public class MyNotiAdapter extends BaseAdapter {

    Context context;
    String[] data;
    String time;
    String Name ;
    String Number;

    private static LayoutInflater inflater = null;
    public MyNotiAdapter(Context context, String[] data,String time, String Name ,String Number) {
        // TODO Auto-generated constructor stub
        this.context = context; = data;
        this.time = time;
        this.Name = Name;
        inflater = (LayoutInflater) context

    public int getCount() {
        // TODO Auto-generated method stub
        return data.length;

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return data[position];

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;

    public int getViewTypeCount() {

     return getCount();

    public int getItemViewType(int position) {

     return position;

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        ViewHolder mHolder;
        View vi = convertView;
        if (vi == null){
            vi = inflater.inflate(R.layout.row2, null);

        mHolder = new ViewHolder();
        mHolder.text= (TextView) vi.findViewById(;
        mHolder.Nameo = (TextView) vi.findViewById(;
        mHolder.Numbero = (TextView) vi.findViewById(;
        mHolder.Time = (TextView) vi.findViewById(;


    }else {
            mHolder = (ViewHolder) convertView.getTag();

        return vi;

    public class ViewHolder {
        public TextView text;
        public TextView Nameo;
        public TextView Numbero;
        public TextView Time;



and here is the activity in which i am setting adapter data...

 public class noticall extends ListActivity {

    CustomDateTimePicker custom;
    TextView tv,tv1;
    EditText ed;
    String store;
    static String Names;
    public static final int PICK_CONTACT = 1;
    String [] adi ;
    static int incre=0;
    ArrayList<String> myrows = new ArrayList<String>();
    private PendingIntent pendingIntent;
    ListView listview;
    String temp1 ,temp2 ;
    int x=0;
    OnItemClickListener listener;
    String Date,Time,Name,Number;
    MyNotiAdapter adp;

        protected void onCreate(Bundle savedInstanceState) {
            listview = (ListView) findViewById(;


            custom = new CustomDateTimePicker(noticall.this,new CustomDateTimePicker.ICustomDateTimeListener() {

               public void onCancel() {

               public void onSet(Dialog dialog, Calendar calendarSelected,Date dateSelected, int year, String monthFullName,
                            String monthShortName, int monthNumber, int date,
                            String weekDayFullName, String weekDayShortName,
                            int hour24, int hour12, int min, int sec,
                            String AM_PM) {

                      Calendar calendar =  Calendar.getInstance();
                      calendar.set(year, monthNumber, date, hour24,  min, 0);

                      long when = calendar.getTimeInMillis();         // notification time

                      Intent myIntent = new Intent(noticall.this, MyReceiver.class);
                      pendingIntent = PendingIntent.getBroadcast(noticall.this, 0, myIntent,0);

                      AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
                      alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), pendingIntent);

        //temp1=  store =calendarSelected.get(Calendar.DAY_OF_MONTH) + "/" + (monthNumber+1) + "/" +
    //  year + ", " + hour12 + ":" + min + " " + AM_PM;

        Date = calendarSelected.get(Calendar.DAY_OF_MONTH) + "/" + (monthNumber+1) + "/" +year;
        Time = hour12 + ":" + min + " " + AM_PM;

        Log.e("Timeee", Time+"");


        Toast.makeText(noticall.this, store, Toast.LENGTH_SHORT).show();


           Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);

             * Pass Directly current time format it will return AM and PM if you set
             * false
             * Pass Directly current data and time to show when it pop up


                    new OnClickListener() {
                        public void onClick(View v) {
                        Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);

         // ((BaseAdapter) listview.getAdapter()).notifyDataSetChanged() ;
         // listview.getAdapter().notifyAll();

     protected void onActivityResult(int requestCode, int resultCode, Intent data)
       super.onActivityResult(requestCode, resultCode, data);

        if(resultCode != RESULT_CANCELED){

            if (requestCode == 1)
                // Get the URI that points to the selected contact
                Uri contactUri = data.getData();

                // We only need the NUMBER column, because there will be only one row in the result
                String[] projection = {ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.CONTACT_ID};

                String[] segments = contactUri.toString().split("/");
                String id = segments[segments.length - 1];

                // Perform the query on the contact to get the NUMBER column
                // We don't need a selection or sort order (there's only one result for the given URI)
                // CAUTION: The query() method should be called from a separate thread to avoid blocking
                // your app's UI thread. (For simplicity of the sample, this code doesn't do that.)
                // Consider using CursorLoader to perform the query.
                Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, projection, null, null, null);
                while (!cursor.isAfterLast())
                    int cid = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
                    String contactid = cursor.getString(cid);

                    if (contactid.equals(id))
                        // Retrieve the phone number from the NUMBER column
                        int column = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
                        String number = cursor.getString(column);

                        // Retrieve the contact name from the DISPLAY_NAME column
                        int column_name = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
                        String name = cursor.getString(column_name);

                        // Do something with the phone number...
                       // Toast.makeText(this, "I added the Contact: \n" + name + " " + number, Toast.LENGTH_SHORT).show();

                       // ed.setText(name+" - "+number);

                      Name=  Names=name;
                      Number =number;  




     public void setlisto(String one ){

     adi = myrows.toArray(new String[myrows.size()]);
     listview.setAdapter(new MyNotiAdapter(noticall.this, adi,Time,Name,Number));

    // ((BaseAdapter) listview.getAdapter()).notifyDataSetChanged();




i have gone through all the solutions provided on internet . i think i am making some mistake somewhere . if anyone can found where the problem lies...?

i Have noticed only Data[] array is updating with different values. but other String variables are overwriting on every item i add.. why is this happening ?

Your code seems need to be refactored a lot.

  • Okay First, create an Model Object class, let say :

    public class MyReminderObject {
      public String date;
      public String time;
      public String name;
      public String number;
  • In your Adapter :

    Add a list of MyReminderObject.

    private List<MyReminderObject> mList;

    Add a new constructor :

    public MyNotiAdapter(Context context) {
      mList = new ArrayList<MyReminderObject>();
      inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Change some methods :

    public int getCount() {
      return mList.size();
    public Object getItem(int position) {
      return mList.get(position);

    In your getView method, change some codes :

    MyReminderObject item = mList.get(position);

    Still in you adapter, add a function to add item :

    public void addReminder(MyReminderObject item){
  • In your Activity :

    in your onCreate() :

    adp = new MyNotiAdapter(noticall.this);

    Lastly, on your setListTo() method :

    public void setlisto(String one ){
      MyReminderObject newItem = new MyReminderObject(); = one;
      newItem.time = Time; = Name;
      newItem.number = Number;