如何从Fragment访问Adapter类中的TextView属性

时间:2016-07-13 08:01:58

标签: android android-fragments landscape

我有一个Fragment类,它有 -

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.my_list, container, false);

        // Set the adapter
        mAdapter = new MyAdapter(getActivity(), null, 0);
        mListView = (AbsListView) view.findViewById(android.R.id.list);
        mListView.setEmptyView(emptyView);
        mListView.setAdapter(mAdapter);

        // Set OnItemClickListener so we can be notified on item clicks
        mListView.setOnItemClickListener(this);

        return view;
    }

@Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        //Save TextView attributes here
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
        //Restore them here   
        }
    }

我有MyAdapter类,其中包含TextView 'time' -

@Override
    public void bindView(View view, Context context, Cursor cursor) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        Child child = children.createStopFromCursor(cursor);

                    viewHolder.time.setText(strText);
                    viewHolder.time.setTextColor(0xff000000);
                    viewHolder.time.setTextSize(17);
                    viewHolder.time.setVisibility(View.VISIBLE);
                    viewHolder.time.setBackgroundColor(nColor);
                    viewHolder.time.setPadding(25,25,25,25);
                    view.invalidate();
        }
    }

我的问题是我想在time中保存textview onSaveInstanceState()的各种属性,例如文字,颜色,填充等,这样当我的手机配置发生变化时,我就可以使用它{{1} }。我如何实现这一目标?

0 个答案:

没有答案