我在listview中有一个已解析的数据。现在我想在listview中集成一个复选框,当它们被选中时,我想将它存储在sqlite数据库中。 知道怎么做。我已经编写了解析和显示的代码,这是我的代码
package com.example.rotaryclubnew;
import java.util.ArrayList;
import java.util.List;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint({ "NewApi", "NewApi", "NewApi" })
public class Displaycontacts extends Activity{
public static String SOAP_ACTION1 = "http://tempuri.org/GetContact";
public static String NAMESPACE = "http://tempuri.org/";
public static String METHOD_NAME1 = "GetContact";
private static String URL = "http://115.119.182.114/Rotaryclub/RotaryService.asmx";
String output="";
ArrayList<String> contactsNamelist;
ArrayList<String> contactsPoslist;
// TextView t1,t2,t3,t4,t5,t6,t7,t8,t9;
ListView lv;
List<String> contactRecords = new ArrayList<String>();
/*
static{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
} */
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.displaycontacts);
lv=(ListView) findViewById(R.id.listViewtodisplayname);
//CALL the web service method with the two parameters vname and nname
Thread networkThread = new Thread() {
@Override
public void run() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION1, envelope);
// final Object response = envelope.getResponse();
// final String str = response.toString();
request.addProperty("user_id", "3");
System.out.println("requesr for"+"3");
envelope.setOutputSoapObject(request);
//httpTransport.call(SOAP_ACTION1, envelope);
final SoapObject result = (SoapObject)envelope.getResponse();
runOnUiThread (new Runnable(){
public void run() {
int count=result.getPropertyCount();
System.out.println("in count "+count);
for (int i = 0; i<= count-1; i++)
{
SoapObject result1=(SoapObject) result.getProperty(i);
contactRecords.add(result1.getProperty(2).toString());
System.out.println("in for loop "+result1.getProperty(2).toString());
// contactRecords.add(result1.getProperty(2).toString());
}
}
});
}
catch (Exception e) {
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
};
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Toast.makeText(getApplicationContext(),"items selected",Toast.LENGTH_LONG).show();
//Intent i1=new Intent(Displaycontacts.this, Displayofcontactsdetails.class);
/*i.putExtra("NAME",lv.getAdapter().getItem(arg2).toString());
i.putExtra("POS",contactsPoslist.get(arg2).toString());
System.out.println("main act put extra "+lv.getAdapter().getItem(arg2).toString()+contactsPoslist.get(arg2).toString());*/
// startActivity(i1);
}
});
networkThread.start();
}
@SuppressWarnings("unused")
private Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(Displaycontacts.this, android.R.layout.simple_list_item_1,contactRecords);
lv.setAdapter(aa);
}
};
}
答案 0 :(得分:0)
如果您想在列表中选中更改的数据库中更新日期,请尝试此
mHolder.mCheckBox.setTag(position);
mHolder.mCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int id = (Integer) buttonView.getTag();
//Write your code for update database over hear and use id to get chacked data position
}
});