title: How to Refresh Custom Adapter List instantly in Android?
body: <p>I am trying to get a list title, What I want is when I type in Edittext on home page then add into list after clicking on Ok button. Right now I don't know where to put my refresh method that I am calling from customAdapter class on Homepage Activity.</p>
  
  <p>Please view my HomePage Activity:</p>
  
  <pre><code>public class Main_Activity extends Activity implements OnClickListener {
  Button ok;
  EditText addTasklist;
  ListView list_tasklistname;
  TodoTask_Database db;
  CustomAdapter cAdapter;
  List&lt;Tasks&gt; list = new ArrayList&lt;Tasks&gt;();
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_layout);
      ok = (Button)findViewById(R.id.add);
      ok.setOnClickListener(this);
      list_tasklistname = (ListView)findViewById(R.id.listview);
      db = new TodoTask_Database(getApplicationContext());
      list = db.getAllTaskList();
      CustomAdapter adapter = new CustomAdapter(Main_Activity.this, R.layout.tasklist_row, list);
      list_tasklistname.setAdapter(adapter);
      /*list_tasklistname.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; adapterView, View v, int position,
                  long id) {
          }
      });*/
      db.close();
  }
  }
  @Override
  public void onClick(View v) {
      switch(v.getId()) {
      case R.id.add:
          addTasklist = (EditText)findViewById(R.id.addTasklist);
          if(addTasklist!=null) {
               String addtasktitle = addTasklist.getText().toString();
               db = new TodoTask_Database(getApplicationContext());
               db.addTaskList(addtasktitle);
          }
          break;
      }
  }
  }
  </code></pre>
  
  <p>Custom Adapter:</p>
  
  <pre><code> public class CustomAdapter extends ArrayAdapter&lt;Tasks&gt; {
  
      private List&lt;Tasks&gt; dataitem;
      private Activity activity;
  
  public CustomAdapter(Activity a, int textViewResourceId, List&lt;Tasks&gt; items) {
      super(a, textViewResourceId, items);
      this.dataitem = items;
      this.activity = a;
  }
  
  public static class ViewHolder{
      public TextView tasklistTitle;
      public TextView createdDate;
      public CheckBox completedflag;
  }
  
     @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View v = convertView;
      ViewHolder holder;
      if (v == null) {
          LayoutInflater vi =
              (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          v = vi.inflate(R.layout.tasklist_row, null);
          holder = new ViewHolder();
          holder.tasklistTitle = (TextView) v.findViewById(R.id.tasklistTitle);
          holder.createdDate = (TextView) v.findViewById(R.id.createdDate);
          holder.completedflag = (CheckBox) v.findViewById(R.id.completedflag);
          v.setTag(holder);
      }
      else
          holder=(ViewHolder)v.getTag();
  
      final Tasks custom = dataitem.get(position);
      if (custom != null) {
          holder.tasklistTitle.setText(custom.getTaskListTitle());
          holder.createdDate.setText(custom.getTaskListCreated());
          holder.completedflag.setText(custom.getTaskListCompletedFlag());
      }
      return v;
  }
    // refresh Adapter Method calling in Homepage Activity
  
     public synchronized void refresAdapter(List&lt;Tasks&gt; dataitems) {   
      dataitem.clear();
      dataitem.addAll(dataitems);
      notifyDataSetChanged();
     }
  }
  </code></pre>