1

由于DirectionalViewPager现在已被弃用,我需要一些方法来模仿它的垂直分页功能。

我想到的第一件事是 ListView,但我想要一些实现每个屏幕功能的提示 - 我从哪里开始?

谢谢。

4

1 回答 1

0
public class Top extends ListActivity {

public void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);
    String[] rows = {1,2,3,4}; //This rows array Determine the no of rows to be displayed on the list
    setContentView(R.layout.top);//layout for activity
    setListAdapter(new MyAdapter(this, R.layout.top_list, R.id.topName, rows);  
}

private class MyAdapter extends ArrayAdapter<String> {

    public MyAdapter(Context context, int resource, int textViewResourceId, String[] objects) 
    {
        super(context, resource, textViewResourceId, objects);          
    }
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) 
        {               
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View row = inflater.inflate(R.layout.top_list, parent, false); //top_list is the seperate layout that represents your list consider it has one TextView.
            String[] rows = {1,2,3,4};          
            TextView tv = (TextView)findViewById(R.id.TextView1);   
            tv.setText(rows[position]);

            return row;
        }           
    }
}

1. Extend ListActivity Instead of Activity.
2. Create two layout one for the Activity and the other for the list.
3. The rows array determine the no of lists in the listview.
4. The position determines the list number.

I hope this helps ask if any other clarification needed.

于 2012-12-12T07:55:33.483 回答