我需要实现具有自动滚动功能的列表视图,直到最后看到列表中的位置意味着当我将该活动运行到第二次然后它应该自动滚动到最后看到的位置,是否有可能在android中,我实现我的数组适配器代码列表如下,请帮帮我:
setListAdapter(new QuestionsArrayAdapter(this, SUBJECT, AUTHOR, RESPONCES, DATETIME, NEWPOST, LOGOIMAGE));
QuestionArratAdapter类是:
public class QuestionsArrayAdapter extends ArrayAdapter<String> {
public QuestionsArrayAdapter(Context context, String[] questions,
String[] author, String[] responces, String[] dateTime,
String[] newPost, String[] logoImage) {
super(context, R.layout.questionscreen, author);
this.context = context;
this.questions = questions;
this.author = author;
this.responces = responces;
this.dateTime = dateTime;
this.newPost = newPost;
this.logoImage = logoImage;
imageLoader=new ImageLoader(context.getApplicationContext());
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//System.out.println(s);
//imageView.setImageResource(R.drawable.image_preview);
return rowView;
}
答案 0 :(得分:2)
您可以在离开活动时保存上次看到的位置;
int position = yourListView.getFirstVisiblePosition();
然后,在第二次参加你的活动时,你可以像这样使用列表视图的平滑滚动方法,
yourListView.smoothScrollToPosition(position);
如果您使用的是this.getListView()
ListActivity
获取您的ListView
答案 1 :(得分:0)
第二次打开活动时,将此属性用于listview
public void smoothScrollToPosition (int position)
代码
listview.smoothScrollToPosition(pos)