I have a simple Android ListView code that displays a list of names that is returned from the web service I have created. I need to add three buttons at the end of the List because:
1) On pressing of each of the 2 buttons the entries marked/checked should be stored in a separate column of my database
2) Submit button to send the data
For storing the data, I am planning to call a webservice when the user clicks the submit button.
My problem is how do I store the checked values for both my buttons? How do I send that data via my webservice?
Also when I run the code below, I am not able to see the buttons
Can anyone please suggest any ideas?
My Android code:
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;
}
}
My displaydata.xml file
<?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"
/>