hi, This is my code:
Sub Globals
Type h (h1 As String,h2 As String,h3 As String,h4 As String,h5 As String)
Dim consultar = "cosultar" As String
Private ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
ejecutar_consulta("SELECT * FROM [XXXXXXXXXXX].[dbo].[VW_ADM_PRODUCTOS]WHERE Existen > 1","consultar")
End Sub
Sub ejecutar_consulta(Query As String,JobName As String)
ProgressDialogShow("Conectando con el servidor...")
Dim job As HttpJob
job.Initialize (consultar, Me)
job.PostString("http://XXXXXXXXXXX\test2.php", Query)
End Sub
Sub jobDone (job As HttpJob)
ProgressDialogHide
If job.Success Then
Dim res As String
res = job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Select job.JobName
Case consultar
Dim nombre As List
nombre = parser.NextArray
For i = 0 To nombre.Size -1
Dim m As Map
m = nombre.Get(i)
Dim h As h
h.h1= m.Get("Descrip")
h.h2= m.Get("Precio1")
h.h3= m.Get("Existen")
h.h4= m.Get("ExExento")
ListView1.AddTwoLines(h.h1,"Precio: "&h.h2)
Next
End Select
Else
ToastMessageShow("Error de conexion", True)
End If
job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim h As h
h = Value
Label6.Text = h.h1
Label10.Text = h.h2
Label4.Text = h.h3
Label3.Text = h.h4
Label8.Text = h.h5
End Sub
Sorry I do not know how to paste my code as in the application hehe
This is the php code
<?php
$serverName="XXXXXXX";
$uid = 'XXXXXX';
$pwd = "XXXXXXXX";
$dbase = "XXXXXXXXXX";
$connectionInfo = array( "Database"=>$dbase, "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$query = file_get_contents("php://input");
$stmt = sqlsrv_query( $conn, $query);
if( $conn === false ) {
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
if( !$stmt ) {
echo "Error executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
$json = array();
do {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$json[] = $row;
}
} while ( sqlsrv_next_result($stmt) );
echo json_encode($json);
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
Ok, I managed to get all the json data in my query, and managed to populate the listview,
But when I click on the list, I can not fill the label with the values, I throw the following error.
Error occurred on line: 82 (AAlistadeprecios)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.samples.sqlserver.aalistadeprecios$_h
atanywheresoftware.b4a.samples.sqlserver.aalistadeprecios._listview1_itemclick(aalistadeprecios.java:553)
I am apprentice
please help.
Sub Globals
Type h (h1 As String,h2 As String,h3 As String,h4 As String,h5 As String)
Dim consultar = "cosultar" As String
Private ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
ejecutar_consulta("SELECT * FROM [XXXXXXXXXXX].[dbo].[VW_ADM_PRODUCTOS]WHERE Existen > 1","consultar")
End Sub
Sub ejecutar_consulta(Query As String,JobName As String)
ProgressDialogShow("Conectando con el servidor...")
Dim job As HttpJob
job.Initialize (consultar, Me)
job.PostString("http://XXXXXXXXXXX\test2.php", Query)
End Sub
Sub jobDone (job As HttpJob)
ProgressDialogHide
If job.Success Then
Dim res As String
res = job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Select job.JobName
Case consultar
Dim nombre As List
nombre = parser.NextArray
For i = 0 To nombre.Size -1
Dim m As Map
m = nombre.Get(i)
Dim h As h
h.h1= m.Get("Descrip")
h.h2= m.Get("Precio1")
h.h3= m.Get("Existen")
h.h4= m.Get("ExExento")
ListView1.AddTwoLines(h.h1,"Precio: "&h.h2)
Next
End Select
Else
ToastMessageShow("Error de conexion", True)
End If
job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim h As h
h = Value
Label6.Text = h.h1
Label10.Text = h.h2
Label4.Text = h.h3
Label3.Text = h.h4
Label8.Text = h.h5
End Sub
Sorry I do not know how to paste my code as in the application hehe
This is the php code
<?php
$serverName="XXXXXXX";
$uid = 'XXXXXX';
$pwd = "XXXXXXXX";
$dbase = "XXXXXXXXXX";
$connectionInfo = array( "Database"=>$dbase, "UID"=>$uid, "PWD"=>$pwd);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$query = file_get_contents("php://input");
$stmt = sqlsrv_query( $conn, $query);
if( $conn === false ) {
echo "Unable to connect.</br>";
die( print_r( sqlsrv_errors(), true));
}
if( !$stmt ) {
echo "Error executing query.</br>";
die( print_r( sqlsrv_errors(), true));
}
$json = array();
do {
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$json[] = $row;
}
} while ( sqlsrv_next_result($stmt) );
echo json_encode($json);
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
?>
Ok, I managed to get all the json data in my query, and managed to populate the listview,
But when I click on the list, I can not fill the label with the values, I throw the following error.
Error occurred on line: 82 (AAlistadeprecios)
java.lang.ClassCastException: java.lang.String cannot be cast to anywheresoftware.b4a.samples.sqlserver.aalistadeprecios$_h
atanywheresoftware.b4a.samples.sqlserver.aalistadeprecios._listview1_itemclick(aalistadeprecios.java:553)
I am apprentice
please help.