Q:

Cant hide custom dialog when item is clicked

This is my dialog onCreate 
protected Dialog onCreateDialog(int id) {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.selection_item,null,false);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setContentView(view);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
    text_noteClick(view);
    checklist_noteClick(view);
    dialog.dismiss();
    return super.onCreateDialog(id);
} 

this is my onClick events 
    public void checklist_noteClick(View v){
    Fragment fragment = null;
    fragment = new Text_Note_Fragment();
    FragmentManager frgManager = getSupportFragmentManager();
    frgManager.beginTransaction().replace(R.id.mainContent, fragment).addToBackStack("gg")
            .commit();
}
public void text_noteClick(View v){
    Fragment fragment = null;
    fragment = new Text_Note_Fragment();
    FragmentManager frgManager = getSupportFragmentManager();
    frgManager.beginTransaction().replace(R.id.mainContent, fragment).addToBackStack("gg")
            .commit();

    removeDialog(getTaskId());
}

I want the dialog to close or hide events in this onClick functions.

A:

I think you set the onClick listener from xml. Try this.
ListView lv = (ListView)dialog.findViewById(R.id.your_listview_id);
lv.setOnClickListener(new View.onClickListener(){
 @Override
 public void onClick(View v){
//your codes
dialog.dismiss();
}
});

Hope this helps. :)

