samedi 14 février 2015

how to call asynctask

I have a web service and this web service return Json string.I want webservice result insert into adapter. But i dont call asynctask class. I've been working on this for 4-5 days and couldn't get it work. Please show me a way to do this...


Note:my code:



public class BakiyeListesi extends Activity {
TextView textmusteriAdi, textBakiye;
ListView listBakiye;
Button backtomusteriAnaSayfasi;
DatabaseTeaApp v3;
List<BakiyeListesiAlanlar> bakiyeler = new ArrayList<BakiyeListesiAlanlar>();

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bakiyeekrani);

textmusteriAdi = (TextView) findViewById(R.id.textMusteriAdi);
textBakiye = (TextView) findViewById(R.id.textBakiyeMarka);
listBakiye = (ListView) findViewById(R.id.listBakiye);
backtomusteriAnaSayfasi = (Button) findViewById(R.id.btnBackToMusteriAnaSayfasi);
v3 = new DatabaseTeaApp(this);

AsyncCallWS callWS = new AsyncCallWS();
callWS.execute();

final BakiyeListesiAdapter adaptorumuz = new BakiyeListesiAdapter(this,
bakiyeler);
listBakiye.setAdapter(adaptorumuz);

backtomusteriAnaSayfasi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
backtomusteriAnaSayfasi.setTextColor(Color.YELLOW);
Intent intent = new Intent(BakiyeListesi.this,
MusteriAnaSayfasi.class);
startActivity(intent);
finish();

}
});

}

public String getproductList(int CustomerID) {
// depo kodu geldi.
String NAMESPACE = "http://ift.tt/1DsLB3r";
String URL = "http://ift.tt/1EtZD3d";
SoapObject request = new SoapObject(NAMESPACE, "CustActivityList");
request.addProperty("CustomerID", CustomerID);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);

envelope.dotNet = true;// web servisimizin .net te yazıldığını
// belirtiyoruz
envelope.setOutputSoapObject(request);

HttpTransportSE senderEnvelope = new HttpTransportSE(URL);

SoapPrimitive result = null;
// bunlaar servisteki ikinci tabloda bulunur.
// soapobject <xsd:schema>schema</xsd:schema>xml</wsTesellumResult>

// SoapPrimitive integer string değerler döndüreceğimiz zaman
// soapAbjectin

try {
// olmazsa while kullan
senderEnvelope.call(
"http://ift.tt/1EtZDju",
envelope);
result = (SoapPrimitive) envelope.getResponse();

} catch (IOException e) {
System.out.println("hatamız:" + e.getMessage());
// TODO Auto-generated catch block
return "-1";
} catch (XmlPullParserException e) {
e.printStackTrace();
// TODO Auto-generated catch block
return "-2";
}
return result.toString();
}

private class AsyncCallWS extends AsyncTask<String, JSONStringer, Void> {

JSONArray jArray;
ProgressDialog pDialog;

@Override
protected Void doInBackground(String... params) {
// takip no:99915984 takipseri: 0000
try {
jArray = new JSONArray(
getproductList(Integer.parseInt(readID(v3))));
} catch (Exception e) {
// TODO: handle exception
}

return null;
}

@Override
protected void onPostExecute(Void result) {

try {

for (int i = 0; i < jArray.length(); i++) {
JSONObject json = jArray.getJSONObject(i);

try {

} catch (Exception e) {
e.printStackTrace();
}

}
// pDialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}

}

@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(BakiyeListesi.this);
pDialog.setMessage("Yükleniyor...");
pDialog.show();
}
}

public String readID(DatabaseTeaApp v1) {
String id = "";
String[] stunlar = { "Id" };
int i = 0;
SQLiteDatabase db = v1.getReadableDatabase();

Cursor okunanlar = db.query("LoginUser", stunlar, null, null, null,
null, null);
while (okunanlar.moveToLast() && i == 0) {
id = okunanlar.getString(okunanlar.getColumnIndex("Id"));
i++;
}

return id;
}
and another class

public class BakiyeListesiAdapter extends BaseAdapter {
private LayoutInflater mInflaterList;
private List<BakiyeListesiAlanlar> BakiyeList;

Activity activityBakiyeList;

BakiyeListesiAdapter(Activity activity, List<BakiyeListesiAlanlar> bakiye) {
// XML'i alıp View'a çevirecek inflater'ı örnekleyelim
mInflaterList = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// gösterilecek listeyi de alalım
BakiyeList = bakiye;
activityBakiyeList = activity;// database için
}

@Override
public int getCount() {
return BakiyeList.size();
}

@Override
public BakiyeListesiAlanlar getItem(int position) {
// şöyle de olabilir: public Object getItem(int position)
return BakiyeList.get(position);
}

@Override//my wiev founction

> `Blockquote`

public long getItemId(int position) {
return position;
}

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View satirView;

// v1=new Database(tAc); database için oluşturulan conscroctur.
satirView = mInflaterList.inflate(R.layout.bakiyeekranialanlar, null);
TextView textBakiyeMarka = (TextView) satirView
.findViewById(R.id.textBakiyeMarka);
TextView textBakiyeMiktar = (TextView) satirView
.findViewById(R.id.textBakiyeMiktar);
TextView textBakiyeUrun = (TextView) satirView
.findViewById(R.id.textBakiyeUrun);

BakiyeListesiAlanlar bakiye = BakiyeList.get(position);

textBakiyeMarka.setText(bakiye.getMarka());
textBakiyeMiktar.setText(bakiye.getMiktar());
textBakiyeUrun.setText(bakiye.getUrun());

if (position % 2 == 0 || position == 0)
satirView.setBackgroundColor(Color.parseColor("#0057a4"));

return satirView;
}

}
Class 3

public class BakiyeListesiAlanlar {
String urun,miktar,marka;

public BakiyeListesiAlanlar(String urun, String miktar, String marka) {
super();
this.urun = urun;
this.miktar = miktar;
this.marka = marka;
}

public String getUrun() {
return urun;
}

public void setUrun(String urun) {
this.urun = urun;
}

public String getMiktar() {
return miktar;
}

public void setMiktar(String miktar) {
this.miktar = miktar;
}

public String getMarka() {
return marka;
}

public void setMarka(String marka) {
this.marka = marka;
}


}




Aucun commentaire:

Enregistrer un commentaire