Я пытаюсь, чтобы моя программа автоматически прокручивалась до целочисленной позиции, заданной глобальным целым числом AtlasApplication.sSlectedPositionForLaw. Я пробовал использовать mNotificationLv.smoothScrollToPostion (AtlasApplication.sSlectedPositionForLaw) без везения в SubMenuActivity. Как заставить SubMenuActivity автоматически прокручивать выбранную позицию в адаптере?Автоматическая прокрутка до позиции в адаптере
SubMenuActivity
@Override
protected void onResume() {
try {
super.onResume();
FontLoader.loadFonts(this);
headerLayout.LoadHeaderFont();
footerLayout.LoadFooterFont();
FontLoader.setRalewayBoldFont(mSubMenuHeaderTv);
FontLoader.setAwesomeFont(mSubMenuBackTv);
FontLoader.setAtlasFont(mSubMenuIconTv);
loadSubMenuLabel();
subMenuAdapter.setList(AtlasApplication.lstLawsForLocation);
mNotificationLv.setAdapter(subMenuAdapter);
mNotificationLv.smoothScrollToPosition(21);
activityResumed();
}
catch(Exception e){
exceptionHandler.handle(e, "onResume()");
}
}
SubMenuAdapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.row_sub_menu_item, null);
holder = new ViewHolder();
holder.rowSubMenuLl = (LinearLayout) convertView.findViewById(R.id.row_sub_menu_ll);
holder.mSubMenuTitleTv = (TextView) convertView.findViewById(R.id.sub_menu_title_tv);
holder.mSubMenuDetailPane = (LinearLayout) convertView.findViewById(R.id.sub_menu_detail_pane_ll);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
FontLoader.setRalewayRegularFont(holder.mSubMenuTitleTv);
LawModel notificationModel = lstSubMenuModels.get(position);
if(Integer.parseInt(notificationModel.getTagID()) == AtlasApplication.sSelectedPositionForLaw) {
notificationModel.setSelected(true);
}
holder.mSubMenuTitleTv.setText(notificationModel.getTagName().trim());
if (notificationModel.isSelected) {
//AtlasApplication.SubMenuTitle = notificationModel.getTagName();
AtlasApplication.sLawModelSelected = notificationModel;
AtlasApplication.sSelectedPositionForLaw=position;
if (holder.mSubMenuDetailPane.getChildCount() < 1) {
SpeedingFines sf = new SpeedingFines(context, holder.mSubMenuDetailPane);
sf.setPriorityListener(mOnPriorityUpdateListener);
holder.rowSubMenuLl.setBackgroundResource(R.color.taxes_bg);
holder.mSubMenuDetailPane.requestFocus();
}
} else {
holder.mSubMenuDetailPane.removeAllViews();
holder.rowSubMenuLl.setBackgroundResource(R.color.grad_dark);
}
holder.mSubMenuTitleTv.setId(position);
holder.mSubMenuTitleTv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
setAllselectedFalse(v.getId());
lstSubMenuModels.get(v.getId()).isSelected = !lstSubMenuModels.get(v.getId()).isSelected;
notifyDataSetChanged();
}
});
return convertView;
}
private void setAllselectedFalse(int selectedRow) {
AtlasApplication.sSelectedPositionForLaw=-1;
for (int i = 0; i < lstSubMenuModels.size(); i++) {
if (i != selectedRow) {
lstSubMenuModels.get(i).setSelected(false);
}
}
}
public void setList(List<LawModel> subMenuModels) {
this.lstSubMenuModels = subMenuModels;
notifyDataSetChanged();
}
private class ViewHolder {
TextView mSubMenuTitleTv;
LinearLayout rowSubMenuLl, mSubMenuDetailPane;
}
Работал как шарм спасибо бутон :) –
добро пожаловать –