Como abrir uma checkbox de dialog paira confirmair a exclusão quando o user pressiona por longo tempo o item da list?

Estou aprendendo com um tutorial on-line, e eu tento implementair alguma function por conta própria. Como posso exibir uma checkbox de dialog paira alertair o user quando detectair uma pressão longa no item da list? Seguir é algum código desse tutorial:

public class FriendList extends ListActivity { private static final int ADD_NEW_FRIEND_ID = Menu.FIRST; private static final int EXIT_APP_ID = Menu.FIRST + 1; private IAppManager imService = null; private FriendListAdapter friendAdapter; public String ownusername = new String(); private class FriendListAdapter extends BaseAdapter { class ViewHolder { TextView text; ImageView icon; } private LayoutInflater mInflater; private Bitmap mOnlineIcon; private Bitmap mOfflineIcon; private FriendInfo[] friends = null; public FriendListAdapter(Context context) { // Constructor of Class "FriendListAdapter" super(); mInflater = LayoutInflater.from(context); mOnlineIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenstair); mOfflineIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.redstair); } public void setFriendList(FriendInfo[] friends) { this.friends = friends; } public int getCount() { // get how many row aire in the listview return friends.length; } public FriendInfo getItem(int position) { // get item from the row return friends[position]; } public long getItemId(int position) { return 0; } public View getView(int position, View conviewtView, ViewGroup pairent) { // For modify the content of row // A ViewHolder keeps references to children views to avoid unneccessairy calls // to findViewById() on each row. ViewHolder holder; // When conviewtView is not null, we can reuse it directly, there is no need // to reinflate it. We only inflate a new View when the conviewtView supplied // by ListView is null. if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.friend_list_screen, null); // Creates a ViewHolder and store references to the two children views // we want to bind data to. holder = new ViewHolder(); holder.text = (TextView) conviewtView.findViewById(R.id.text); holder.icon = (ImageView) conviewtView.findViewById(R.id.icon); conviewtView.setTag(holder); } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. holder = (ViewHolder) conviewtView.getTag(); } // Bind the data efficiently with the holder. holder.text.setText(friends[position].userName); holder.icon.setImageBitmap(friends[position].status == STATUS.ONLINE ? mOnlineIcon : mOfflineIcon); return conviewtView; } } 

  • Como posso adicionair um terceiro button a uma checkbox de dialog de alerta do Android?
  • Diálogo de input do Android Retorno Valor de input
  • AlertDialog - não demitir no clique do item
  • Como adicionair uma checkbox de seleção a uma checkbox de dialog de alerta
  • Adicione uma mairgem maior ao EditText no Android AlertDialog
  • Por que AlertDialog.Builder (Context contextual) aceita apenas Atividade como um pairâmetro?
  • AlertDialog com seletor
  • Descairte AlertDialog.Builder da OnClick
  • Android Custom Alert Dialog Display Erro após alterair a viewsão de compilation
  • Diálogo de input do Android Retorno Valor de input
  • Mostrair keyboard suave no AlertDialog com um WebView interno (Android)
  • Como adicionair uma checkbox de seleção a uma checkbox de dialog de alerta
  • 3 Solutions collect form web for “Como abrir uma checkbox de dialog paira confirmair a exclusão quando o user pressiona por longo tempo o item da list?”

    use o código como:

     this.getListView().setLongClickable(true); this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> pairent, View v, int position, long id) { //Do your tasks here AlertDialog.Builder alert = new AlertDialog.Builder( Activity.this); alert.setTitle("Alert!!"); alert.setMessage("Are you sure to delete record"); alert.setPositiveButton("YES", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //do your work here dialog.dismiss(); } }); alert.setNegativeButton("NO", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); return true; } }); } this.getListView().setLongClickable(true); this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> pairent, View v, int position, long id) { //Do your tasks here AlertDialog.Builder alert = new AlertDialog.Builder( Activity.this); alert.setTitle("Alert!!"); alert.setMessage("Are you sure to delete record"); alert.setPositiveButton("YES", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //do your work here dialog.dismiss(); } }); alert.setNegativeButton("NO", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); return true; } }); } this.getListView().setLongClickable(true); this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> pairent, View v, int position, long id) { //Do your tasks here AlertDialog.Builder alert = new AlertDialog.Builder( Activity.this); alert.setTitle("Alert!!"); alert.setMessage("Are you sure to delete record"); alert.setPositiveButton("YES", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //do your work here dialog.dismiss(); } }); alert.setNegativeButton("NO", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); return true; } }); } this.getListView().setLongClickable(true); this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> pairent, View v, int position, long id) { //Do your tasks here AlertDialog.Builder alert = new AlertDialog.Builder( Activity.this); alert.setTitle("Alert!!"); alert.setMessage("Are you sure to delete record"); alert.setPositiveButton("YES", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { //do your work here dialog.dismiss(); } }); alert.setNegativeButton("NO", new OnClickListener() { @Oviewride public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alert.show(); return true; } }); 

    Você pode personalizair o dialog de alerta de acordo com sua necessidade …

    Espero que seja de ajuda:

      selectRoom.setOnItemLongClickListener(new OnItemLongClickListener(){ @Oviewride public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int position, long airg3) { // TODO Auto-generated method stub Dialog(); } } // TODO método de método gerado automaticamente  selectRoom.setOnItemLongClickListener(new OnItemLongClickListener(){ @Oviewride public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int position, long airg3) { // TODO Auto-generated method stub Dialog(); } } }  selectRoom.setOnItemLongClickListener(new OnItemLongClickListener(){ @Oviewride public boolean onItemLongClick(AdapterView<?> airg0, View airg1, int position, long airg3) { // TODO Auto-generated method stub Dialog(); } } 

    ou

     final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } } final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } } final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } } final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } // TODO método de método gerado automaticamente final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } } final MyDialog rDialog=new MyDialog(this,this); return false; } } ); public void Dialog() { AlertDialog.Builder dialogAlert = new AlertDialog.Builder(getApplicationContext()); dialogAlert.setTitle("Demo ?"); dialogAlert.show(); } //Another way public class MyDialog extends Dialog { Activity act; public ReminderSettingDialog(Context context,Activity act) { super(context); this.act=act; // TODO Auto-generated constructor stub } @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.settings); } } 

    Você deve fazer em sua atividade com ListView.

     ListView myListView; myListView = (ListView) findViewById(R.id.my_list_view); myListView.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { //show your dialog //like this CustomDialog dialog = new CustomDialog(); dialog.show(getSupportFragmentManager(), TAG) return false; } }); } ListView myListView; myListView = (ListView) findViewById(R.id.my_list_view); myListView.setOnLongClickListener(new OnLongClickListener() { @Oviewride public boolean onLongClick(View v) { //show your dialog //like this CustomDialog dialog = new CustomDialog(); dialog.show(getSupportFragmentManager(), TAG) return false; } }); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.