Android Listview populates previous listview from AWS Simpledb If I run the select QUERY with a different item name in the same domain. However everything works fine only if I clear my phone's memory caches manually or exit my application with System.exit(0); However my goal is to to be able to populate a new current listview without exiting the application.
I don't know if this is a memory leak issue or how best to fix this.
I will paste relevant part of the codes. Please help. A simplified explanatory answer will be appreciated. Thanks.
public class JegeCardAdapter extends ArrayAdapter<JegeCard> {
protected LayoutInflater mInflater;
//initialize variable
protected List<JegeCard> jjj = new ArrayList<JegeCard>();
public JegeCardAdapter(Context context, int resourceId) {
super(context, resourceId);
// TODO Auto-generated constructor stub
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount(){
return jjj.size();
}
public JegeCard getItem(int pos) {
return jjj.get(pos);
}
public void removeItemAt(int pos) {
this.jjj.remove(pos);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
final JegeCard myJegeCards = this.getItem(pos);
// make sure we have a view to work with
View itemView = convertView;
if (itemView == null) {
itemView = mInflater.inflate(R.layout.jege_itemview, parent, false);
}
// fill the view
TextView cardname = (TextView) itemView.findViewById(R.id.username_tv);
cardname.setText(myJegeCards.getCardName());
TextView cardnumber = (TextView) itemView.findViewById(R.id.password_tv); //ignore the password_tv
cardnumber.setText(myJegeCards.getCardNumber());
TextView cvv = (TextView) itemView.findViewById(R.id.bank_tv);
cvv.setText(myJegeCards.getCardCvv());
return itemView;
}
public List<JegeCard> getMyJegeCards(){
return jjj;
}
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jege_mainview);
addACard = (Button) findViewById(R.id.addCardfinal);
addACard.setOnClickListener(this);
listview = (ListView) findViewById(R.id.jegelistview);
new GetMyJegeCardsTask().execute();
new GetTotalCountTask().execute();
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// TODO Auto-generated method stub
JegeCard clickedJegeCard = myJegeCardAdapter.getItem(position);
// set up a toast message
// String message = "You clicked position " + position
// + " which is itemName: "
// + clickedJegeCard.getCardName();
// Toast.makeText(UserHomeViewActivity.this, message,
// Toast.LENGTH_SHORT).show();
// Hold the item name clicked
clickedCardName = clickedJegeCard.getCardName();
clickedCardNumber = clickedJegeCard.getCardNumber();
clickedCardCvv = clickedJegeCard.getCardCvv();
startActivity(new Intent(UserHomeViewActivity.this,
DeleteCardActivity.class));
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.addCardfinal:
startActivity(new Intent(UserHomeViewActivity.this,
AddNewCardActivity.class));
break;
}
}
private class GetMyJegeCardsTask extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... voids) {
boolean shouldRefresh = false;
JegeControlTwo jct = new JegeControlTwo();
myJegeCardAdapter = new JegeCardAdapter(UserHomeViewActivity.this,
R.layout.jege_itemview);
List<JegeCard> list = null;
if (myJegeCardAdapter.getMyJegeCards().size() == 0) {
list = jct.getUserCreditCards();
myJegeCardAdapter.getMyJegeCards().addAll(list);
shouldRefresh = true;
} else {
list = jct.getNextPageOfScores();
myJegeCardAdapter.getMyJegeCards().addAll(list);
shouldRefresh = true;
}
return shouldRefresh;
}
protected void onPostExecute(Boolean shouldRefresh) {
if (shouldRefresh) {
if (listview.getAdapter() != null) {
myJegeCardAdapter.notifyDataSetChanged();
} else {
listview.setAdapter(myJegeCardAdapter);
}
}
}
}
........
Android Listview populates previous listview from AWS Simpledb If I run the select QUERY with a different item name in the same domain. However everything works fine only if I clear my phone's memory caches manually or exit my application with System.exit(0); However my goal is to to be able to populate a new current listview without exiting the application.
I don't know if this is a memory leak issue or how best to fix this.
I will paste relevant part of the codes. Please help. A simplified explanatory answer will be appreciated. Thanks.
public class JegeCardAdapter extends ArrayAdapter<JegeCard> {
protected LayoutInflater mInflater;
//initialize variable
protected List<JegeCard> jjj = new ArrayList<JegeCard>();
public JegeCardAdapter(Context context, int resourceId) {
super(context, resourceId);
// TODO Auto-generated constructor stub
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount(){
return jjj.size();
}
public JegeCard getItem(int pos) {
return jjj.get(pos);
}
public void removeItemAt(int pos) {
this.jjj.remove(pos);
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
final JegeCard myJegeCards = this.getItem(pos);
// make sure we have a view to work with
View itemView = convertView;
if (itemView == null) {
itemView = mInflater.inflate(R.layout.jege_itemview, parent, false);
}
// fill the view
TextView cardname = (TextView) itemView.findViewById(R.id.username_tv);
cardname.setText(myJegeCards.getCardName());
TextView cardnumber = (TextView) itemView.findViewById(R.id.password_tv); //ignore the password_tv
cardnumber.setText(myJegeCards.getCardNumber());
TextView cvv = (TextView) itemView.findViewById(R.id.bank_tv);
cvv.setText(myJegeCards.getCardCvv());
return itemView;
}
public List<JegeCard> getMyJegeCards(){
return jjj;
}
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jege_mainview);
addACard = (Button) findViewById(R.id.addCardfinal);
addACard.setOnClickListener(this);
listview = (ListView) findViewById(R.id.jegelistview);
new GetMyJegeCardsTask().execute();
new GetTotalCountTask().execute();
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
// TODO Auto-generated method stub
JegeCard clickedJegeCard = myJegeCardAdapter.getItem(position);
// set up a toast message
// String message = "You clicked position " + position
// + " which is itemName: "
// + clickedJegeCard.getCardName();
// Toast.makeText(UserHomeViewActivity.this, message,
// Toast.LENGTH_SHORT).show();
// Hold the item name clicked
clickedCardName = clickedJegeCard.getCardName();
clickedCardNumber = clickedJegeCard.getCardNumber();
clickedCardCvv = clickedJegeCard.getCardCvv();
startActivity(new Intent(UserHomeViewActivity.this,
DeleteCardActivity.class));
}
});
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.addCardfinal:
startActivity(new Intent(UserHomeViewActivity.this,
AddNewCardActivity.class));
break;
}
}
private class GetMyJegeCardsTask extends AsyncTask<Void, Void, Boolean> {
protected Boolean doInBackground(Void... voids) {
boolean shouldRefresh = false;
JegeControlTwo jct = new JegeControlTwo();
myJegeCardAdapter = new JegeCardAdapter(UserHomeViewActivity.this,
R.layout.jege_itemview);
List<JegeCard> list = null;
if (myJegeCardAdapter.getMyJegeCards().size() == 0) {
list = jct.getUserCreditCards();
myJegeCardAdapter.getMyJegeCards().addAll(list);
shouldRefresh = true;
} else {
list = jct.getNextPageOfScores();
myJegeCardAdapter.getMyJegeCards().addAll(list);
shouldRefresh = true;
}
return shouldRefresh;
}
protected void onPostExecute(Boolean shouldRefresh) {
if (shouldRefresh) {
if (listview.getAdapter() != null) {
myJegeCardAdapter.notifyDataSetChanged();
} else {
listview.setAdapter(myJegeCardAdapter);
}
}
}
}
........
0 commentaires:
Enregistrer un commentaire