Android Listview不令人耳目一新

时间:2016-03-25 11:16:08

标签: android listview

我知道它回答了很多次,但不知何故不适合我。我试过每一个" Listview没有刷新"线程但仍然没有运气。我无法刷新我的listview。我做错了什么?当我调试代码时,我可以在dty列表中看到新项目,但listview没有显示。

    public class BuzagiListAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private List<BuzagiKayitDBean> mBuzagiList;
    Context context;


    public BuzagiListAdapter(List<BuzagiKayitDBean> sorgu, Activity activity) {

        mInflater = (LayoutInflater) activity.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        mBuzagiList = sorgu;


    }

    public void add(List<BuzagiKayitDBean>  buz) {
        for(BuzagiKayitDBean item :buz)
        {
            mBuzagiList.add(item);
        }
        notifyDataSetChanged();

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

    @Override
    public BuzagiKayitDBean getItem(int position) {
        return mBuzagiList.get(position);
    }

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

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

        View satirView;

        satirView = mInflater.inflate(R.layout.buzagilist_row, null);
        TextView textView =
                (TextView)        satirView.findViewById(R.id.txtblDogumSonucuandKupeNo);
        TextView textView2 =
                (TextView) satirView.findViewById(R.id.txtblCinsiyetandPadok);


        BuzagiKayitDBean buz = mBuzagiList.get(position);

        textView.setText(buz.getDogumSonuc() + "-" + buz.getKupeNo());
        textView2.setText(buz.getCinsiyet() + " -" + buz.getGidecegiPadok());
        return satirView;


    }
        public void updateNewList(ArrayList<BuzagiKayitDBean> array){
        mBuzagiList = array;
        notifyDataSetChanged();

       }
    }      

  @Override
protected void onActivityResult(int requestCode, int resultCode, Intent  data) {
    // TODO Auto-generated method stub

    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 2) {

        String kpn = data.getStringExtra("kupeno");
        txtddtyKupeNo.setText(kpn);


    }
    if (resultCode == 3) {

        ArrayList<BuzagiKayitDBean> arraylist =    data.getParcelableArrayListExtra("mylist");
        BuzagiKayitDBean buzd = new BuzagiKayitDBean();
        adapter = new BuzagiListAdapter(dty, BuzagiKayitActivity.this);
        for (BuzagiKayitDBean item : arraylist) {

            buzd.setGidecegiPadok(item.getGidecegiPadok());
            buzd.setKupeNo(item.getKupeNo());
            buzd.setCinsiyet(item.getCinsiyet());
            buzd.setDogumSonuc(item.getDogumSonuc());


        }
        dty.add(buzd);
          if(adapter == null){
            adapter = new BuzagiListAdapter(dty, BuzagiKayitActivity.this);
            buzlist.setAdapter(adapter);
        }else{
            adapter.updateNewList((ArrayList<BuzagiKayitDBean>)dty);
        }      

    }
}``

1 个答案:

答案 0 :(得分:0)

Try ths:    
if (resultCode == 3) {

            ArrayList<BuzagiKayitDBean> arraylist =    data.getParcelableArrayListExtra("mylist");
            for (BuzagiKayitDBean item : arraylist) {
                BuzagiKayitDBean buzd = new BuzagiKayitDBean();
                buzd.setGidecegiPadok(item.getGidecegiPadok());
                buzd.setKupeNo(item.getKupeNo());
                buzd.setCinsiyet(item.getCinsiyet());
                buzd.setDogumSonuc(item.getDogumSonuc());
                dty.add(buzd);
            }
             if(adapter == null){
            adapter = new BuzagiListAdapter(dty, BuzagiKayitActivity.this);
            buzlist.setAdapter(adapter);
        }else{
            adapter.add(dty);
        }