Listview在添加新项目后没有刷新

时间:2016-03-25 09:37:24

标签: android listview

首先,它不是我的主要语言,我知道我的英语sux。我无法刷新我的listview。我做错了什么?当我调试代码时,我可以在dty列表中看到新项目但listview没有显示。

编辑:更新了代码,但仍然没有运气 MyAdapter:

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)

创建适配器后,您在public class FullVersion extends AppCompatActivity implements IabBroadcastListener { Intent intent = null; boolean mIsPremium = false; static final String SKU_PREMIUM = "IAP-NAME"; static final int RC_REQUEST = 10001; IabHelper mHelper; IabBroadcastReceiver mBroadcastReceiver; Button BuyFullVersion; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fullversion); BuyFullVersion = (Button) findViewById(R.id.BuyFullVersion); BuyFullVersion.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String payload = ""; mHelper.launchPurchaseFlow(FullVersion.this, SKU_PREMIUM, RC_REQUEST, mPurchaseFinishedListener, payload); } }); String base64EncodedPublicKey = "XXXXXXXXX"; mHelper = new IabHelper(this, base64EncodedPublicKey); mHelper.enableDebugLogging(true); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { if (!result.isSuccess()) { // GOOGLE ACCOUNT MISSING return; } if (mHelper == null) return; mBroadcastReceiver = new IabBroadcastReceiver(FullVersion.this); IntentFilter broadcastFilter = new IntentFilter(IabBroadcastReceiver.ACTION); registerReceiver(mBroadcastReceiver, broadcastFilter); mHelper.queryInventoryAsync(mGotInventoryListener); } }); } IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() { public void onQueryInventoryFinished(IabResult result, Inventory inventory) { if (mHelper == null) return; if (result.isFailure()) { Log.e("-->","Failed to query inventory: " + result); return; } if (result.isFailure()) { Log.e("-->", "ERROR"); } else { if (inventory.hasPurchase(SKU_PREMIUM) == true) { // SET SHARED PREFERENCES BOOLEAN "FULLVERSION" = TRUE } } Purchase premiumPurchase = inventory.getPurchase(SKU_PREMIUM); mIsPremium = (premiumPurchase != null && verifyDeveloperPayload(premiumPurchase)); } }; @Override public void receivedBroadcast() { mHelper.queryInventoryAsync(mGotInventoryListener); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (mHelper == null) return; if (!mHelper.handleActivityResult(requestCode, resultCode, data)) { super.onActivityResult(requestCode, resultCode, data); } } boolean verifyDeveloperPayload(Purchase p) { return true; } IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() { public void onIabPurchaseFinished(IabResult result, Purchase purchase) { if (mHelper == null) { return; } if (result.isFailure()) { Log.e("-->","Error purchasing: " + result); return; } if (purchase.getSku().equals(SKU_PREMIUM)) { mHelper.consumeAsync(purchase, mConsumeFinishedListener); } if (!verifyDeveloperPayload(purchase)) { Log.e("-->","Error purchasing. Authenticity verification failed."); return; } } }; IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener() { public void onConsumeFinished(Purchase purchase, IabResult result) { if (mHelper == null) return; if (result.isSuccess()) { // SET SHARED PREFERENCES BOOLEAN "FULLVERSION" = TRUE } else { Log.e("-->","Error while consuming: " + result); } } }; } 中添加了一个值。它应该是这样的:

dty

您的适配器

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(dty);
}