如何使用自定义 arrayAdapter 在 onPostExecute 中列出 mssql 记录.我编写了以下代码,但



我想在android listview中列出我的mssql记录。这是我的代码;

活动;

public class YoneticiMenuActivity extends Activity {
JSONObject jsonObject = null;
//JSONArray jsonArray = null;
//public Is isler = new Is();
//public ArrayList<Is> arrayIsler = new ArrayList<Is>();
ListView lvTumIsler;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_yonetici_menu);
    Intent iAl = getIntent();
    String mesaj = iAl.getStringExtra(LoginActivity.m);
    int mode = Activity.MODE_PRIVATE;
    SharedPreferences mSP;
    mSP = getSharedPreferences(mesaj, mode);
    String baslik = mSP.getString("name", "") + " " + mSP.getString("surname", "") + ", Hoşgeldiniz";
    setTitle(baslik);
    lvTumIsler = (ListView)findViewById(R.id.lvTumIsler);
    new AsyncTaskYonetici("Veriler yükleniyor...").execute();
}
private class AsyncTaskYonetici extends AsyncTask<Void, Void, Void> {
    String modalMesaj;
    ProgressDialog dialog;
    JSONArray jsonArray = null;
    JSONObject jsonObject = null;
    public Is isler = new Is();
    public ArrayList<Is> arrayIsler = new ArrayList<Is>();
    //private ListView lvTumIsler;

    public AsyncTaskYonetici(String mMesaj) {
        this.modalMesaj = mMesaj;
        this.dialog = new ProgressDialog(YoneticiMenuActivity.this);
    }
    @Override
    protected void onPreExecute() {
        dialog.setMessage(modalMesaj);
        dialog.setIndeterminate(true);
        dialog.setCancelable(false);
        dialog.show();
    }
    @Override
    protected Void doInBackground(Void... params) { 
        String url = "http://www.saklambacjeans.com/skbos/webServiceTumIsler.aspx";
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet(url);
        HttpResponse response;
        try {
            response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream instream = entity.getContent();
                BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
                String line = null;
                try {
                    if ((line = reader.readLine()) != null) {
                        jsonArray = new JSONArray(line);                        
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    try {
                        instream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }                    
            }
        } catch (ClientProtocolException e) {
            Mesaj(e.getMessage());
        } catch (IOException e) {
            Mesaj(e.getMessage());
        } /*catch (JSONException e) {
            Mesaj(e.getMessage());
        }*/
        return null;
    }
    @Override
    protected void onPostExecute(Void str) {
        try {
            for (int i = 0; i < jsonArray.length(); i++) 
            {
                jsonObject = jsonArray.getJSONObject(i);
                isler.setP(Integer.parseInt(jsonObject.getString("urunId").toString()),
                           Integer.parseInt(jsonObject.getString("modelNo").toString()),
                           jsonObject.getString("modelAd").toString(),
                           jsonObject.getString("bedenAd").toString(),
                           Integer.parseInt(jsonObject.getString("adet").toString()),
                           jsonObject.getString("aciklama").toString(), 
                           jsonObject.getString("kesmeTalimat").toString(), 
                           jsonObject.getString("atolyeTalimat").toString(), 
                           jsonObject.getString("yıkamaTalimat").toString(),
                           jsonObject.getString("utuTalimat").toString(), 
                           jsonObject.getString("kesimci").toString(),
                           jsonObject.getString("atolyeci").toString(), 
                           jsonObject.getString("yıkamacı").toString(), 
                           jsonObject.getString("utucu").toString(), jsonObject.getString("kontrolcu").toString());
                arrayIsler.add(isler);  
            }       
        } catch (JSONException e) {
            e.printStackTrace();
        }
        IsAdapter adapter = new IsAdapter(YoneticiMenuActivity.this, R.layout.layouttumisler, arrayIsler);
        lvTumIsler.setAdapter(adapter);
        if (dialog.isShowing())
            dialog.dismiss();
    }
}
private void Mesaj(String s) {
    Toast.makeText(this, s, Toast.LENGTH_LONG).show();
}

我的适配器;

public class IsAdapter extends ArrayAdapter<Is> {
private ArrayList<Is> arrayIsler;
Context context;
public IsAdapter(Context context, int layoutResourceId, ArrayList<Is> a) {
    super(context, layoutResourceId, a);
    this.arrayIsler = a;
    this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    if (row == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = inflater.inflate(R.layout.layouttumisler, null);
    }
    Is is = arrayIsler.get(position);
    if (is != null) {
        TextView tvId = (TextView) row.findViewById(R.id.tvId);
        TextView tvModel = (TextView) row.findViewById(R.id.tvModel);
        TextView tvAtolye = (TextView) row.findViewById(R.id.tvAtolye);
        TextView tvUrunId = (TextView) row.findViewById(R.id.tvUrunId);
        TextView tvUrunModel = (TextView) row.findViewById(R.id.tvUrunModel);
        TextView tvUrunAtolye = (TextView) row.findViewById(R.id.tvUrunAtolye);
        if (tvId != null){
            tvId.setText("Ürün No: ");
        }
        if (tvUrunId != null){
            tvUrunId.setText(is.getId());
        }
        if (tvModel != null){
            tvModel.setText("Model: ");
        }
        if (tvUrunModel != null){
            tvUrunModel.setText(is.getModel());
        }
        if (tvAtolye != null){
            tvAtolye.setText("Atolye: ");
        }
        if (tvUrunAtolye != null){
            tvUrunAtolye.setText(is.getAtolye());
        }
    }
    return row;
}   

}

我的是类;

public class Is {
public int urunId;
public int modelNo;
public String modelAd;
public String bedenAd;
public int adet;
public String aciklama;
public String kesmeTalimat;
public String atolyeTalimat;
public String yikamaTalimat;
public String utuTalimat;
public String kesimci;
public String atolyeci;
public String yikamaci;
public String utucu;
public String kontrolcu;
public int getId() {return urunId;}
public String getModel() {return modelAd;}
public String getAtolye() {return atolyeci;}
public void setP(int u, int mN, String mA, String bA, int a, String ac, String kT, String aT, String yT, String uT,
        String k, String at, String y, String utu, String ko)
{
urunId = u;
modelNo = mN;
modelAd = mA;
bedenAd = bA;
adet = a;
aciklama = ac;
kesmeTalimat = kT;
atolyeTalimat = aT;
yikamaTalimat = yT;
utuTalimat = uT;
kesimci = k;
atolyeci = at;
yikamaci = y;
utucu = utu;
kontrolcu = ko;
}

}

我在主布局中使用列表视图,在布局图姆斯勒中有 6 个文本视图。我在myAsyncTask的onPostExecute中使用IsAdapter,但是当我执行应用程序时,它停止了。mssql 记录确实来自 Web 服务,但我无法列出。我在IsAdapter getView中出错,在

tvUrunId.setText(is.getId());

请帮帮我...

当我

改变时,我犯了一个严重的错误

public int getId() {return urunId;}

public String getId() 
{
    String s = Integer.toString(urunId);
    return s;
}

代码有效。

最新更新