Good afternoon
I'm already finishing an app in Android Studio, I'm just detailing, but I find a detail that I have not been able to solve, what happens is that I have a listview
with a custom view, in which in the custom view I have a Edittext
for the user to put a quantity and in the bottom part a button to record the amount and send it by webservices.
But the problem is that when I want to position on the Edittext
that I have it as a numeric type, it does not show me the cursor in the Edittext
so it does not show me the numeric keyboard, if I put it in Landscape if he shows me the keyboard without problems ...
The application emulated using Genymotion, I attached an image.
I leave my code of layout
and my activity
.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Folio"
android:id="@+id/textView2"
android:textSize="14dp"
android:textColor="#060000"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="FOLIO FACTURA"
android:id="@+id/txtFolio"
android:textSize="14dp"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:layout_toEndOf="@+id/textView2"
android:layout_marginLeft="2dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Fecha"
android:id="@+id/textView4"
android:textSize="14dp"
android:textColor="#060000"
android:layout_marginLeft="58dp"
android:layout_marginStart="58dp"
android:layout_alignTop="@+id/textView2"
android:layout_toRightOf="@+id/txtFolio"
android:layout_toEndOf="@+id/txtFolio" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="FECHA"
android:id="@+id/txtFecha"
android:textSize="14dp"
android:layout_alignTop="@+id/txtFolio"
android:layout_toRightOf="@+id/textView4"
android:layout_toEndOf="@+id/textView4"
android:layout_marginLeft="2dp" />
</RelativeLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Total"
android:id="@+id/textView3"
android:layout_column="1"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Saldo_total"
android:id="@+id/textView5"
android:layout_column="4"
android:layout_marginLeft="5dp"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="@string/Saldo_Vencidode"
android:id="@+id/textView6"
android:layout_column="7"
android:layout_marginLeft="20dp"
android:textSize="13dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"></TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0.00"
android:id="@+id/total"
android:layout_column="1"
android:layout_gravity="right"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0.00"
android:id="@+id/txttotal"
android:layout_column="4"
android:layout_marginLeft="5dp"
android:layout_gravity="right"
android:textColor="#090808"
android:textSize="13dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="0.00"
android:id="@+id/txtvencido"
android:layout_column="7"
android:layout_marginLeft="-1dp"
android:layout_gravity="right"
android:textColor="#f90a0a"
android:textSize="13dp" />
<EditText
android:layout_width="80dp"
android:layout_height="wrap_content"
android:inputType="number|numberDecimal"
android:ems="10"
android:hint="@string/hint_abono"
android:id="@+id/edt_abono"
android:layout_column="20"
android:layout_gravity="left"
android:layout_marginLeft="60dp"
android:textSize="15dp" />
</TableRow>
</TableLayout>
Activity
import android.Manifest;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class Detalle_Cliente extends AppCompatActivity{
ProgressDialog dialog;
TextView resultado;
ListView list;
ArrayList<DetalleCxP> DetalleArrayList = new ArrayList<DetalleCxP>();
MyArrayAdapter adaptador;
AlertDialog alert = null;
CXCPSaldoClienteProveedor O_Cliente;
DetalleMenu O_DetalleMenu;
private TextView lblLatitud;
private TextView lblLongitud;
private LocationManager locManager;
private LocationListener locListener;
TextView direccion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent1=getIntent();
setContentView(R.layout.activity_detalle__cliente);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//Inicializan datos de ubicacion
lblLatitud = (TextView) findViewById(R.id.LblPosLatitud);
lblLongitud = (TextView) findViewById(R.id.LblPosLongitud);
lblLongitud.getTag();
direccion = (TextView)findViewById(R.id.direccion);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Aqui van los comentarions",Toast.LENGTH_SHORT).show();
}
});
Intent intentt=getIntent();
O_DetalleMenu=(DetalleMenu) intentt.getSerializableExtra("O_DetalleMenu");
Intent intent=getIntent();
O_Cliente=(CXCPSaldoClienteProveedor) intent.getSerializableExtra("O_Cliente");
setTitle(O_Cliente.getClienteDescripcion());
//codigo listview
list=(ListView)this.findViewById(R.id.listDeta);
comenzarLocalizacion();
AsyncCallWSDetalle task = new AsyncCallWSDetalle();
//Call execute
task.execute();
//Codigo Boton de Pagar
Button pagar = (Button)this.findViewById(R.id.btnpago);
pagar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog.Builder alert = new AlertDialog.Builder(Detalle_Cliente.this);
alert.setMessage("¿Estas Seguro de Aplicar el Abono?");
alert.setTitle("Confirmacion");
alert.setPositiveButton("Aceptar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
comenzarLocalizacion();
AsyncGrabarCXCP task = new AsyncGrabarCXCP();
//Call execute
task.execute();
}
});
alert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alert.show();
//Validar();
// adaptador.notifyDataSetChanged();
}
});
}
private void comenzarLocalizacion() {
//Obtenemos una referencia al LocationManager
locManager =
(LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Obtenemos la última posición conocida
Location loc =
locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
//Mostramos la última posición conocida
mostrarPosicion(loc);
//Nos registramos para recibir actualizaciones de la posición
locListener = new LocationListener() {
public void onLocationChanged(Location location) {
if(location.getLatitude() != 0.0D && location.getLongitude() != 0.0D) {
try {
Geocoder e = new Geocoder(Detalle_Cliente.this, Locale.getDefault());
List list = e.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if(!list.isEmpty()) {
Address DirCalle = (Address)list.get(0);
direccion.setText("Mi direccion es: \n" + DirCalle.getAddressLine(0));
}
} catch (IOException var5) {
var5.printStackTrace();
}
}
}
public void onProviderDisabled(String provider) {
//lblEstado.setText("Provider OFF");
}
public void onProviderEnabled(String provider) {
//lblEstado.setText("Provider ON ");
}
public void onStatusChanged(String provider, int status, Bundle extras) {
/*Log.i("", "Provider Status: " + status);
lblEstado.setText("Provider Status: " + status);*/
}
};
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
locManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1500, 0, locListener);
}
private void mostrarPosicion(Location loc) {
if(loc != null)
{
lblLatitud.setText("Latitud: " + String.valueOf(loc.getLatitude()));
lblLongitud.setText("Longitud: " + String.valueOf(loc.getLongitude()));
//lblPrecision.setText("Precision: " + String.valueOf(loc.getAccuracy()));
Log.i("", String.valueOf(loc.getLatitude() + " - " + String.valueOf(loc.getLongitude())));
}
else
{
lblLatitud.setText("Latitud: (sin_datos)");
lblLongitud.setText("Longitud: (sin_datos)");
//lblPrecision.setText("Precision: (sin_datos)");
}
}
//Codigo Para Grabar docuemnto
private class AsyncCallWSDetalle extends AsyncTask<String, ArrayList, ArrayList> {
@Override
protected ArrayList doInBackground(String... params){
DetalleArrayList=webService.DetalleCxP(O_Cliente.getCliente());
return null;
}
@Override
//Make Progress Bar visible
protected void onPreExecute() {
dialog=new ProgressDialog(Detalle_Cliente.this);
dialog.setIndeterminate(false);
dialog.setMessage("Cargando Detalle...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected void onProgressUpdate(ArrayList... values) {
super.onProgressUpdate(values);
}
//Once WebService returns response
@Override
protected void onPostExecute(ArrayList arrayList) {
super.onPostExecute(arrayList);
if(DetalleArrayList.size()!=0){
dialog.dismiss();
adaptador= new MyArrayAdapter(Detalle_Cliente.this, DetalleArrayList);///* no se usa your_array_list
ListView listView = (ListView) findViewById(R.id.listDeta);
listView.setAdapter(adaptador);
adaptador.notifyDataSetChanged();
}else{
dialog.dismiss();
}
}
}
public class MyArrayAdapter extends ArrayAdapter<DetalleCxP> {
public MyArrayAdapter(Context context, ArrayList<DetalleCxP> ArrayClientes) {
super(context, 0, ArrayClientes);
}
public View getView(int position, View convertView, ViewGroup parent) {
DetalleCxP O_DetalleCxP = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null)
{
convertView = LayoutInflater.from(getContext()).inflate(R.layout.row_detalle, parent, false);
EditText ET_Abono = (EditText) convertView.findViewById(R.id.edt_abono);
//attach the TextWatcher listener to the EditText
ET_Abono.addTextChangedListener(new TB_Abono_Watcher(convertView));
}
//Obteniendo instancias de los text views
TextView fecha = (TextView)convertView.findViewById(R.id.txtFecha);
TextView folio = (TextView)convertView.findViewById(R.id.txtFolio);
TextView vencido = (TextView)convertView.findViewById(R.id.txtvencido);
TextView saldo = (TextView)convertView.findViewById(R.id.txttotal);
EditText Abono = (EditText) convertView.findViewById(R.id.edt_abono);
TextView total = (TextView)convertView.findViewById(R.id.total);
DecimalFormat numberFormat = new DecimalFormat("###,##0.00");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
fecha.setText(dateFormat.format(O_DetalleCxP.getFecha()));
folio.setText(O_DetalleCxP.getFolio());
Abono.setTag(O_DetalleCxP);
if (O_DetalleCxP.TotalAplicado>0)
{
Abono.setText(numberFormat.format(O_DetalleCxP.TotalAplicado));
}
else
{
Abono.setText("");
}
total.setText(numberFormat.format(O_DetalleCxP.getTotal()));
saldo.setText(numberFormat.format(O_DetalleCxP.getSaldo()));
vencido.setText(numberFormat.format(O_DetalleCxP.getSaldoVencido()));
//Devolver al ListView la fila creada
return convertView;
}
}
//Clae para Edittext
private class TB_Abono_Watcher implements TextWatcher{
Button pagar = (Button)findViewById(R.id.btnpago);
private View view;
private TB_Abono_Watcher(View view) {
this.view = view;
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
/*if(s.toString().trim().length()==0){
pagar.setEnabled(false);
} else {
pagar.setEnabled(true);
}*/
//do nothing
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//do nothing
}
public void afterTextChanged(Editable s)
{
EditText ET_Abono = (EditText) view.findViewById(R.id.edt_abono);
DetalleCxP O_DetalleCxP = (DetalleCxP)ET_Abono.getTag();
O_DetalleCxP.TotalAplicado=ONC_SYS.NullToZeroDouble(s.toString());
}
}
//Medoto para Grabar datos
public class AsyncGrabarCXCP extends AsyncTask<Void,Integer,String>
{
int Recurso;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog=new ProgressDialog(Detalle_Cliente.this);
dialog.setIndeterminate(false);
dialog.setMessage("Procesando Datos...");
dialog.setCancelable(false);
dialog.show();
}
@Override
protected String doInBackground(Void... params) {
String Resultado="";
Recurso=webService.ObtenerRecurso();
String Folio = webService.ObtenerFolio(35);
Date O_D = new Date();
Double Factor=0.0, Importe=0.0, Descuento=0.0, SubTotal=0.0, Total=0.0, IVA=0.0,Retencion1=0.0,Retencion2=0.0,IEPS=0.0;
Double DFactor=0.0;
for(int i=0;i<DetalleArrayList.size();i++) {
Factor=0.0;
if (((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado>0)
{
Factor = ((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado / ((DetalleCxP)DetalleArrayList.get(i)).Total;
Importe += ((DetalleCxP)DetalleArrayList.get(i)).Importe*Factor;
Descuento += ((DetalleCxP)DetalleArrayList.get(i)).Descuento*Factor;
SubTotal += ((DetalleCxP)DetalleArrayList.get(i)).SubTotal*Factor;
IVA += ((DetalleCxP)DetalleArrayList.get(i)).IVA*Factor;
Retencion1 += ((DetalleCxP)DetalleArrayList.get(i)).Retencion1*Factor;
Retencion2 += ((DetalleCxP)DetalleArrayList.get(i)).Retencion2*Factor;
IEPS += ((DetalleCxP)DetalleArrayList.get(i)).IEPS*Factor;
Total += ((DetalleCxP)DetalleArrayList.get(i)).Total*Factor;
String resultado=String.valueOf(Total);
}
}
Resultado = webService.LLenarEncabezadoCXCP(Recurso,
"I", //Accion I
0, //Id = 0
O_Cliente.getEmpresa(), //Id de Empresa
Folio,
new Date(),
O_Cliente.getCliente(),
O_Cliente.getProveedor(),
O_Cliente.getMoneda(),
1.0, //Tipo de Cambio por default 1
0, //Cuenta Bancaria
"hugo", //Usuario Captura
6, //Pago Forma
Total, //Saldo
Importe, //Importe
0, //Financiamiento
Descuento,
SubTotal,
Retencion1,
Retencion2,
IEPS,
IVA,
0, //ISH,
Total, //Total
Total, //totalaplicado,
"A", //status,
"", //usucariocancela,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, //Numero1...Numero10
"","","","","","","","","","", //Texto1...Texto10
new Date(),new Date(),new Date(),new Date(),new Date(),new Date(), //Fecha1...Texto6
"", //Observacion
0,0,0,0,0,0, //Catalogo1...Catalogo6
"", //ordencompra
0, //concepto
"", //observacioncancelacion
0, //origenventacompra,
0 //origeninventario
);
if (Resultado.equals("OK"))
{
for(int i=0;i<DetalleArrayList.size();i++) {
if (((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado>0)
{
DFactor = ((DetalleCxP)DetalleArrayList.get(i)).TotalAplicado / ((DetalleCxP)DetalleArrayList.get(i)).Total;
Resultado = webService.LLenarDetalleCXCP(Recurso,
"I", //Accion
0, //id
((DetalleCxP)DetalleArrayList.get(i)).getId(), //Origen
((DetalleCxP)DetalleArrayList.get(i)).getDocumento(), //OrigenDocumento
(Double)(((DetalleCxP)DetalleArrayList.get(i)).Importe*DFactor), //Importe
(Double)0.0, //Financiamiento
(Double)(((DetalleCxP)DetalleArrayList.get(i)).Descuento*DFactor), //Descuento
(Double)(((DetalleCxP)DetalleArrayList.get(i)).SubTotal*DFactor), //Subtotal
(Double)(((DetalleCxP)DetalleArrayList.get(i)).Retencion1*DFactor), //Retencion1
(Double)(((DetalleCxP)DetalleArrayList.get(i)).Retencion2*DFactor), //Retencion2
(Double)(((DetalleCxP)DetalleArrayList.get(i)).IEPS*DFactor), //IEPS
(Double)(((DetalleCxP)DetalleArrayList.get(i)).IVA*DFactor), //IVA
(Double)0.0, //ISH
(Double)(((DetalleCxP)DetalleArrayList.get(i)).Total*DFactor), //Total
((DetalleCxP)DetalleArrayList.get(i)).getSaldo(), //Saldo
"Android App" //Referencia
);
}
}
}
if (Resultado.equals("OK"))
{
Resultado = webService.GrabarCxCP(Recurso,//Recurso
O_DetalleMenu.getModulo(), //Modulo
O_DetalleMenu.getOperacion(), //Operacion
O_DetalleMenu.getDocumento(), //Documento
0, //OrigenId
0); //OrigenDocumento
}
return null;
}
@Override
protected void onPostExecute(String Resultado) {
super.onPostExecute(Resultado);
Toast.makeText(getApplicationContext(), "Datos Guardados Correctamente", Toast.LENGTH_SHORT).show();
finish();
dialog.dismiss();
}
/* if ((Resultado == "OK"))
{
try {
Toast.makeText(getApplicationContext(), "Datos Guardado Correctamente", Toast.LENGTH_SHORT).show();
finish();
dialog.dismiss();
}catch (Exception e){
Toast.makeText(getApplicationContext(), "Error en el Webservices" + e.toString(), Toast.LENGTH_LONG).show();
dialog.dismiss();
}
}*/
}
public DetalleCxP FindCXCPSaldoClienteProveedorById(int Id)
{
for(int i=0;i<DetalleArrayList.size();i++)
{
if (DetalleArrayList.get(i).getId()==Id)
{
return DetalleArrayList.get(i);
}
}
return null;
}
}