How to delete Mysql database news?

Asked

Viewed 164 times

1

At this link teaches to list comments (in my case news) using external database (has the project download).

How can I delete a news item when selecting, and still cause a dialog to appear asking if I want to delete the news from the external database?

This is the code of INSERT:

public void chamaCadastrarNoticia(){
    setContentView(R.layout.cadastrar_noticia);

    editTituloNoticia=(EditText) findViewById(R.id.editTituloNoticia);
    editNoticia=(EditText) findViewById(R.id.editNoticia);
    btCadastrarNoticia=(Button) findViewById(R.id.btCadastrarNoticia);

    btCadastrarNoticia.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {                
            String vazios = "";
            if (editTituloNoticia.getText().toString().equals("")) 
                vazios="Campo Titulo não pode estar vazio\n\n"; 

            if (editNoticia.getText().toString().equals("")) 
                vazios="Campo Noticia não pode estar vazio\n\n";            

            if  (editTituloNoticia.getText().toString().equals("") || editNoticia.getText().toString().equals("")) 
                mensagemExibir("Erro:", ""+vazios);
            else {                
                String urlPost="#url"; // URL
                String urlGet="#url   ?titulo="+editTituloNoticia.getText().toString()+"noticia="+editNoticia.getText().toString(); // URL
                ArrayList<NameValuePair> iparametrosPost = new ArrayList<NameValuePair>();
                iparametrosPost.add(new BasicNameValuePair("titulo",editTituloNoticia.getText().toString()));   
                iparametrosPost.add(new BasicNameValuePair("noticia",editNoticia.getText().toString()));            
                String respostaRetornada = null;

                try {
                    respostaRetornada = ConexaoHttpClient.executaHttpPost(urlPost, iparametrosPost);
                    String resposta = respostaRetornada.toString();
                    resposta = resposta.replaceAll("\\s+", "");

                    if (resposta.equals("1")) {
                        mensagemExibir("Cadastrado:", "Acesse Listar Noticias para ver a noticia cadastrada");
                    }

                    chamaIndexAdmin();
                }
                catch(Exception erro){
                    Log.i("erro", "erro = "+erro);
                    mensagemExibir("Erro", "Erro ao gravar: "+erro);
                }
            }
        }
    });     
}
  • you’ve already managed to do the INSERT?

  • yes, I want to use this project to list news (it worked out) but I can’t implement to delete them

  • has how you show me how to delete from the database, using this project you’ve got to download

  • I don’t think I’ll need to download; your question is a little wide, but if you have already managed to do the delete Insert is mt similar, could you show us how you do the Insert? edit your question to enter the code

  • I did not do the Insert using the project there, I made a mix, porderia do separate but I need to urgently solve this problem, when I downloaded the project, I managed to list there I joined the code with my old project

  • There’s the guy who says he can use onItemClick for future modifications but he doesn’t teach to delete =(

  • pera minto, I made the INSERT in my project, I will send

  • @Math looks at her in question the INSERT code

  • the code is totally different, do not use JSON in the code of the Insert

  • personal help =(

Show 5 more comments

1 answer

2

To submit a confirmation to the user you can use the Dialog, placing a request to the server on the positive button.

To delete a comment ( news, in your case ), I believe that the best option is to create a new service ( removeComment.php, for example ) that will be called and pass as parameter some identifier of the news ( recommend to be the own identifier of the table of the database )

From there just update the list on the device

  • in my case I created excluirNoticias.php but I try to implement the function of deleting it in Onitemclick and always from the error. Is there any way you could download the project and show me how it’s done? It only shows to list, now delete no =( last week it’s been 1 month that I’m trying and nothing, help me

Browser other questions tagged

You are not signed in. Login or sign up in order to post.