У меня есть простой код Android ListView, который отображает список имен, который возвращается из созданного мной веб-сервиса. Мне нужно добавить три кнопки в конце списка, потому что:
1) При нажатии каждой из 2 кнопок отмеченные / отмеченные записи должны храниться в отдельном столбце моей базы данных
2) Кнопка «Отправить» для отправки данных
Для хранения данных я планирую вызвать веб-службу, когда пользователь нажимает кнопку отправки.
Моя проблема в том, как сохранить проверенные значения для обеих моих кнопок? Как отправить эти данные через мой веб-сервис?
Также, когда я запускаю приведенный ниже код, я не могу видеть кнопки
Может кто-нибудь предложить какие-нибудь идеи?
Мой код 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;
}
}
Мой файл 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"
/>