I want pass values from a form making with TextInputLayout but Android Studio detects my content as INT. I put the complete class of my activity as well as the view in .xml to determine the problem
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.prosegma.rso.R;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class AccionActivity extends AppCompatActivity {
ImageView imageView;
private Context activity;
private String[]header={"Campo","Respuesta"};
private String shortText="RSO PROSEGMA";
private String longText="Eliminamos Riesgos Sumamos Valor";
private AccionPdf accionPdf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_accion);
Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
imageView = (ImageView)findViewById(R.id.reporte1);
btnCamera1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
}
});
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
accionPdf=new AccionPdf(getApplicationContext());
accionPdf.openDocument();
accionPdf.addMetaData("Reporte","Acción Insegura","www.prosegma.com");
accionPdf.addTitle("Reporte Acción Insegura","RSO Prosegma"," " +timeStamp);
accionPdf.addParagraph(shortText);
accionPdf.addParagraph(longText);
accionPdf.createTable(header,getClients());
accionPdf.closeDocument();
}
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
private ArrayList<String[]>getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport });
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}
public void pdfAccion(View view)
{
accionPdf.verReporteAccion();
}
public void enviarA(View view) {
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, "receiver_email_address");
email.putExtra(Intent.EXTRA_SUBJECT, "subject");
email.putExtra(Intent.EXTRA_TEXT, "email body");
Uri uri = Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory(), "pdfFileName"));
email.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("application/pdf");
email.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getActivity().startActivity(email);
}
public Context getActivity() {
return activity;
}
}
I update the publication with the activity, I have tried to change the InputTextLayout by EditText but the situation is the same, it throws me an incompatibility error.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/actionbar_toolbar"/>
<ScrollView
android:id="@+id/reportes0"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:id="@+id/reportes1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:weightSum="10"
>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
/>
<View
android:layout_width="match_parent"
android:layout_height="7dp"
/>
<ImageView
android:id="@+id/reporte1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/BtnCamera1"
android:layout_weight="1"
android:layout_height="64sp"
android:layout_width="64sp"
android:background="@drawable/camera"
android:gravity="center"
/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/nReporta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="NOMBRE DE QUIEN REPORTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/nTrabajador"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="NOMBRE DEL TRABAJADOR"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/eContratista"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="EMPRESA CONTRATISTA"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextBlack"
android:layout_marginTop="4dp"
>
<android.support.design.widget.TextInputEditText
android:id="@+id/aMedidas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:hint="ACCIÓN, MEDIDAS CORRECTIVAS INMEDIATAS"
android:inputType="textShortMessage"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/EditTextBlack"
android:layout_marginTop="4dp"
>
</android.support.design.widget.TextInputLayout>
<CheckBox
android:id="@+id/checkAccidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ACCIDENTE" />
<CheckBox
android:id="@+id/checkImpacto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="IMPACTO AMBIENTAL" />
<CheckBox
android:id="@+id/checkEnfermedad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ENFERMEDAR PROFESIONAL" />
<CheckBox
android:id="@+id/checkReincidente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REINCIDENTE" />
<CheckBox
android:id="@+id/checkSancion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="¿APLICA SANCIÓN?"
/>
<Button
android:id="@+id/guardarAccion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GUARDAR REPORTE"
android:theme="@style/RaisedButtonDark"
android:onClick="pdfAccion"
/>
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
TextInputEditText Nreport = (TextInputEditText) findViewById(R.id.nReporta);
this line is outside OnCreate(Bundle savedInstanceState) method. Thats why it throws null. It should be like this
public class MainActivity extends AppCompatActivity {
TextInputEditText Nreport;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Button btnCamera1 = (Button)findViewById(R.id.BtnCamera1);
// imageView = (ImageView)findViewById(R.id.reporte1);
Date date = new Date();
String timeStamp = new SimpleDateFormat("dd/MM/yyyy").format(date);
Nreport = (TextInputEditText) findViewById(R.id.nReporta);
getClients();
}
private ArrayList<String[]> getClients(){
ArrayList<String[]>rows=new ArrayList<>();
rows.add(new String[]{"Nombre de quien reporta", Nreport.getText().toString() }); // get text like this
rows.add(new String[]{"Nombre del trabajador","No"});
rows.add(new String[]{"Empresa contratista","ju"});
rows.add(new String[]{"Medidas Necesarias","hu"});
return rows;
}