Hi, how to refresh listView when clicked again in another action. I use a database where I delete a specific row in one Activity , if it is pressed alone, it is not updated. When I switch to some other activity or close the application and open, it works fine where the listView updated.
Here is the code ..
public class FragmentLiveChats extends Fragment { private AdapterLiveChat adapterChatHistory; private List<LiveChatDetails> customerDetail; private ListView mListView; private List<LiveChatDetails> list; @Override public void onViewCreated(View view, Bundle savedInstanceState) { list =AAEDatabaseHelper.getLiveChatDetails(Constants.TABLE_LIVE_CHAT); mListView = (ListView) rootView.findViewById(R.id.list_chat_history); parseResponse(); } private void parseResponse(){ for(int i=0;i<list.size();i++){ LiveChatDetails chatDetailsList = new LiveChatDetails(); chatDetailsList.setId(list.get(i).getId()); chatDetailsList.setFromUsername(list.get(i).getFromUsername()); chatDetailsList.setChatTime(list.get(i).getChatTime()); chatDetailsList.setLatMsg(list.get(i).getLatMsg()); customerDetail.add(chatDetailsList); } setValuesInAdapter(); } @Override public void onResume() {
In the adapter:
public void setExpertData(List<LiveChatDetails> mTempData) { this.mTempData = mTempData; }
In ExpertChatView activity, I delete the entry, and if I come to this screen, i.e. by pressing the previous action, it still remains the same list and is not updated. But when I close the application and open it, it works fine.
In expertChatView activity, I delete the username entry.
AAEDatabaseHelper.deleteUsername(<username>);
I tried using the notifyDatasetChanged method in onResume() , but still the same question.
EDIT
Adapter class public class AdapterLiveChat extends BaseAdapter { private Context context; private List<LiveChatDetails> mTempData; private LayoutInflater mInflater; private LiveChatDetails liveChatDetails; private View adView; private ViewHolder holder; private String userImageUrl; public AdapterLiveChat(Context context) { this.context = context; imgLoader = Picasso.with(context); mCalendar = Calendar.getInstance(); } public void setExpertData(List<LiveChatDetails> mTempData) { this.mTempData = mTempData; } public void updateList(List<LiveChatDetails> mChatDetails) { this.mTempData = mChatDetails; } @Override public int getCount() { return mTempData.size(); } @Override public LiveChatDetails getItem(int position) { return mTempData.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { mInflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); liveChatDetails = getItem(position); adView = convertView; if (adView == null) { holder = new ViewHolder(); adView = mInflater.inflate(R.layout.row_live_chats, null); holder.txtName = (CustomTextView) adView .findViewById(R.id.txt_name); adView.setTag(holder); } else holder = (ViewHolder) adView.getTag(); holder.txtName.setText(liveChatDetails.getFromUsername()); return adView; }
// consider the owner class here ...
source share