0

**I have a row.xml file to my listview i trying use a button in my row to send a email but that button dont work ** i used this comand to take a button but he do anyting

i put a button but it seams that nothing heapining in the button i put a event in there

public class row extends AppCompatActivity {
Button btnEnviarEmail;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.row);

        btnEnviarEmail=findViewById(R.id.BtnEnviarEmail);
        btnEnviarEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
>here is my intent i dont know why its not working
                 //Criando a Intent
                String[] TO={""};
                String[]CC={""};
                Intent intent=new Intent(Intent.ACTION_SEND);
                intent.setData(Uri.parse("mailto"));
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_CC,CC);
                intent.putExtra(Intent.EXTRA_EMAIL,TO);
                intent.putExtra(Intent.EXTRA_SUBJECT,"Enter your body for subject");
                intent.putExtra(Intent.EXTRA_TEXT,"Body of the Mail");
                try {

                    startActivity(Intent.createChooser(intent,"Sending Email"));


                }catch (android.content.ActivityNotFoundException ex ){

                    ex.printStackTrace();//impossibilita a aplicação de crashar

                }




            }
        });


    }


}```


[enter image description here][1]


  [1]: https://i.stack.imgur.com/Yy1r7.jpg
>thats my adapter i wanna get the email text to send automatically you know?
**When i get the field txtEmail so i put auto in my mensage**

public View getView(int position, View convertView, ViewGroup parent) {

    View row=convertView;
    ViewHolder holder=new ViewHolder();
    if (row==null){
        LayoutInflater inflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        row=inflater.inflate(layout,null);
        holder.txtnome=row.findViewById(R.id.txtNome);
        Button pegarEmail=(Button)row.findViewById(R.id.BtnEnviarEmail);
        pegarEmail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Criando a Intent
                String[] TO={""};
                String[]CC={""};
                Intent intent=new Intent(Intent.ACTION_SEND);
                intent.setData(Uri.parse("mailto"));
                intent.setType("text/plain");
                intent.putExtra(Intent.EXTRA_CC,CC);
                intent.putExtra(Intent.EXTRA_EMAIL,TO);
                intent.putExtra(Intent.EXTRA_SUBJECT,"Enter your body for subject");
                intent.putExtra(Intent.EXTRA_TEXT,"Body of the Mail");
                try {

                    context.startActivity(Intent.createChooser(intent,"Sending Email"));


                }catch (android.content.ActivityNotFoundException ex ){

                    ex.printStackTrace();//impossibilita a aplicação de crashar

                }


            }
        });
        holder.txttelefone=row.findViewById(R.id.txtTelefone);
        holder.txtdataNascimento=row.findViewById(R.id.txtDataNascimento);
        holder.txtEmail=row.findViewById(R.id.txtEmail);
        holder.txtprovidencia=row.findViewById(R.id.txtProvidencias);

        holder.imageView=row.findViewById(R.id.imgIcon);
        row.setTag(holder);



    }

    else {
        holder=(ViewHolder)row.getTag();
    }

    Model model =recordList.get(position);
    holder.txtnome.setText(model.getNome());
    holder.txttelefone.setText(model.getTelefone());
    holder.txtdataNascimento.setText(model.getDataNascimento());
    holder.txtEmail.setText(model.getEmail());
    holder.txtprovidencia.setText(model.getProvidencias());

    byte[] recordImage=model.getImage();
    Bitmap bitmap = BitmapFactory.decodeByteArray(recordImage,0,recordImage.length);
    holder.imageView.setImageBitmap(bitmap);



    return row;


    //Criando a Intent
    //impossibilita a aplicação de crashar

}```
JhonPeter
  • 21
  • 5
  • Does this answer your question? [Android : How to set onClick event for Button in List item of ListView](https://stackoverflow.com/questions/12596199/android-how-to-set-onclick-event-for-button-in-list-item-of-listview) – Tyler V Nov 25 '21 at 21:29
  • no man this dont get the field email you know? – JhonPeter Nov 25 '21 at 21:55
  • Did you even read the question? If your button is in a row in a ListView you cannot access it in `onCreate` like you have done - you have to set this in the adapter for the ListView (in `getView`) – Tyler V Nov 25 '21 at 22:14
  • Also, are you trying to create an Activity for each row in the ListView? That's not how it's done at all - try searching for some ListView tutorials to go through. – Tyler V Nov 25 '21 at 22:21
  • @TylerV No its just a button for any item in my listView just that i just wanna send a email to my friends, in listview . – JhonPeter Nov 25 '21 at 22:39
  • If "row.xml" is supposed to go in a ListView then what you have posted is totally wrong. If that is not the case, then you need to post a complete example so someone else could run it too (including the xml). – Tyler V Nov 25 '21 at 22:48
  • Then why does it say `public class row extends AppCompatActivity`? There is no ListView adapter in the code you posted - that is an Activity. Take a look [here](https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) for some examples of adapters. – Tyler V Nov 25 '21 at 22:54
  • @TylerV sorry i put my adapter now i really dont know how explain myself but i wanna send to they a email with "happy birthday and get the field date" to send in his birthday. – JhonPeter Nov 25 '21 at 23:07
  • one problem is the statement do acept the date variable – JhonPeter Nov 25 '21 at 23:07
  • Have you had a look at [this example](https://stackoverflow.com/questions/8701634/send-email-intent)? You have a bunch of different questions here and it's hard to know what you're asking. Are you asking how to make a button in a ListView do something, or are you asking how to make a button (anywhere) send an email? – Tyler V Nov 25 '21 at 23:08
  • @TylerV sorry what i want i a button who will send a email, when the birthday is equal to system date and that will be automatically send one email of "happy birthday" – JhonPeter Nov 26 '21 at 03:16
  • @TylerV its clear now ? sorry if what i said had be confused to you – JhonPeter Nov 26 '21 at 03:17
  • What do you want to happen if you press the button and it is not the person's birthday? Nothing? Or it queues up an email to be sent some time in the future? You can't make it automatically send the email - all it will do is launch the user's email app. – Tyler V Nov 26 '21 at 03:25
  • @TylerV nothing will happen except open email box to send another email but remember in my sqlite will be several persons so several emails will ned be send. – JhonPeter Nov 26 '21 at 03:47
  • @TylerV i look your post down here but in my sqlite listview is a field call "txtNascimento" its a birthday so i put that like string but i wanna take that and if are equals to system then send email but i wanna if possible just one button in my activity who will verify if sistem date is equal to "txtdataNascimento". the if equals will send the will verify ever one in sqlite and send if was equals – JhonPeter Nov 26 '21 at 03:55
  • You need to ask specific individual questions on Stackoverflow - you asked how to send an email when you click a button. Now you are asking about comparing dates to data stored in SQL. Open a new question if you have a new question and ask specifically what you want. – Tyler V Nov 26 '21 at 05:42

0 Answers0