J'ai un simple code Android ListView qui affiche une liste de noms qui est retournée par le service Web que j'ai créé. Je dois ajouter trois boutons à la fin de la liste parce que:Afficher un bouton pour stocker des données dans une base de données dans un Android ListView
1) En appuyant sur chacun des 2 boutons les entrées marquées/vérifiés doivent être stockés dans une colonne séparée de ma base de données
2) Continuer bouton pour envoyer les données
Pour stocker les données, je prévois d'appeler un service Web lorsque l'utilisateur clique sur le bouton Soumettre.
Mon problème est de savoir comment stocker les valeurs cochées pour mes deux boutons? Comment envoyer ces données via mon webservice?
Aussi quand je lance le code ci-dessous, je ne suis pas en mesure de voir les boutons
Quelqu'un peut-il s'il vous plaît suggérer des idées?
Mon code Android:
package com.example;
import java.net.SocketException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
public class display extends Activity {
private static final String SOAP_ACTION = "http://tempuri.org/getData";
private static final String METHOD_NAME = "getData";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://10.0.2.2/getdata2/Service1.asmx";
TextView tv;
private ListView lView;
private Button markpresent;
private Button markabsent;
private Button submit;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.displaydata);
tv=(TextView)findViewById(R.id.text1);
String[] arr2= call();
lView = (ListView) findViewById(R.id.ListView01);
//Set option as Multiple Choice. So that user can able to select more the one option from list
lView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, arr2));
lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
markpresent = (Button) findViewById(R.id.Button01);
markpresent.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//put checked entries in database
}
});
markabsent = (Button) findViewById(R.id.Button02);
markabsent.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//put checked entries in database
}
});
submit = (Button) findViewById(R.id.Button03);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//call another web service for insertion of data
}
});
}
//webservice call works fine
public String[] call()
{
SoapPrimitive responsesData = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
responsesData = (SoapPrimitive) envelope.getResponse();
System.out.println(" --- response ---- " + responsesData);
} catch (SocketException ex) {
ex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(" ----" + responsesData);
String serviceResponse= responsesData .toString();
String[] temp;
String delimiter = "#";
temp= serviceResponse.split(delimiter);
System.out.println(" ---- length ---- " + temp.length);
return temp;
}
}
Mon fichier displaydata.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:id="@+id/ListView01" android:layout_height="wrap_content"
android:layout_width="fill_parent"></ListView>
<Button
android:layout_height="wrap_content"
android:id="@+id/Button01" android:text="Mark present"
android:layout_width="fill_parent"
/>
<Button
android:layout_height="wrap_content"
android:id="@+id/Button02" android:text="Mark absent"
android:layout_width="fill_parent"
/>
S'il vous plaît postez votre fichier xml car il aidera à aller au fond de pourquoi vos boutons ne s'affichent pas. – Craigy
@Craigy: oui ajouté –