List of usage examples for android.widget ListView setStackFromBottom
public void setStackFromBottom(boolean stackFromBottom)
From source file:com.googlecode.networklog.LogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MyLog.d("[LogFragment] onCreateView"); LinearLayout layout = new LinearLayout(getActivity().getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); ListView listView = new ListView(getActivity().getApplicationContext()); listView.setAdapter(adapter);//from w ww . j a va2s . c om listView.setTextFilterEnabled(true); listView.setFastScrollEnabled(true); listView.setSmoothScrollbarEnabled(false); listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); listView.setStackFromBottom(true); listView.setOnItemClickListener(new CustomOnItemClickListener()); layout.addView(listView); registerForContextMenu(listView); startUpdater(); return layout; }
From source file:org.egov.android.view.activity.AllComplaintActivity.java
/** * The onResponse method will be invoked after the all complaint API call. onResponse methods * will contain the response.If the response has a status as 'success' then we have checked * whether the access token is valid or not.If the access token is invalid, redirect to login * page. If the access token is valid, the response contains the JSON object. * createdDate,complainantName,detail,crn,status values are retrieved from the response object * and store it to the variable then these values are set to the all complaint layout. call the * _addDownloadJobs method to display the complaint photo from the complaint photos directory on * the storage device. displays the All complaints list with the corresponding complaint image. * we have checked the pagination value.This value is retrieved from the api response if the * value is true then load more option will be displayed below the complaint list view. *//*from ww w. j a va2 s .c o m*/ @Override public void onResponse(Event<ApiResponse> event) { String status = event.getData().getApiStatus().getStatus(); String pagination = event.getData().getApiStatus().isPagination(); String msg = event.getData().getApiStatus().getMessage(); final ListView listView = (ListView) getActivity().findViewById(R.id.all_complaint_list); if (!toAppend) { listItem = new ArrayList<Complaint>(); } if (status.equalsIgnoreCase("success")) { try { if (listItem.size() > 5) { listItem.remove(listItem.size() - 1); } JSONArray ja = new JSONArray(event.getData().getResponse().toString()); Complaint item = null; isApiLoaded = true; if (ja.length() > 0) { ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.GONE); for (int i = 0; i < ja.length(); i++) { JSONObject jo = ja.getJSONObject(i); item = new Complaint(); String userName = _getValue(jo, "complainantName"); item.setCreatedDate(_getValue(jo, "createdDate")); item.setCreatedBy((userName.equals("")) ? _getValue(jo, "lastModifiedBy") : userName); item.setDetails(_getValue(jo, "detail")); item.setComplaintId(jo.getString("crn")); item.setStatus(jo.getString("status")); StorageManager sm = new StorageManager(); Object[] obj = sm.getStorageInfo(AllComplaintActivity.this.getActivity()); String complaintFolderName = obj[0].toString() + "/complaints/" + jo.getString("crn"); File complaintFolder = new File(complaintFolderName); if (!complaintFolder.exists()) { if (jo.getInt("supportDocsSize") == 0) { item.setImagePath( complaintFolderName + File.separator + "photo_complaint_type.jpg"); } else { item.setImagePath(complaintFolderName + File.separator + "photo_" + jo.getInt("supportDocsSize") + ".jpg"); } sm.mkdirs(complaintFolderName); _addDownloadJobs(complaintFolderName, jo); } else { item.setImagePath(complaintFolderName + File.separator + "photo_" + complaintFolder.listFiles().length + ".jpg"); } listItem.add(item); } if (listItem.size() > 5) { listView.postDelayed(new Runnable() { public void run() { listView.setStackFromBottom(true); listView.setSelection(listItem.size() - 8); } }, 0); } if (pagination.equals("true")) { item = new Complaint(); listItem.add(item); } ServiceController.getInstance().startJobs(); _displayListView(pagination.equals("true")); } else if (listItem.size() == 0) { ((TextView) getActivity().findViewById(R.id.all_errMsg)).setVisibility(View.VISIBLE); _displayListView(false); } } catch (JSONException e) { e.printStackTrace(); } } else { if (msg.matches(".*Invalid access token.*")) { _showMsg("Session expired"); AndroidLibrary.getInstance().getSession().edit().putString("access_token", "").commit(); Intent intent = new Intent(getActivity(), LoginActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent); getActivity().finish(); } else { page = (page > 1) ? page - 1 : 1; _showMsg(msg); } } }