保存复选框各国通过在Android的碎片 [英] Save checkboxes states through fragments in Android

查看:181
本文介绍了保存复选框各国通过在Android的碎片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个应用程序有两个列表(在不同的片段)与复选框。

I'm currently working on an app with a two lists (in different fragments) with checkboxes.

几张截图向您展示的显示方式:

A few screenshots to show you the display :

会谈屏幕

论文屏幕

现在,我想能够

1)保存所有的复选框与各国«保存键(并与«负载»按钮)加载它们。

1) save all the checkboxes states with the «save» button (and load them with the «load» button)

2)链接复选框,这样如果我点击一个在六方会谈的屏幕就被点击过的论文屏幕。

2) "link" the checkboxes so that if I click on one in the Talks screens it gets clicked too in the Papers Screens.

我知道我可以通过使用共享preferences保存这些,但它们是建立一个适配器,因此我只有,比如

I know I could save these by using SharedPreferences, but they are build with an adapter and so all I have is, for instance

    @Override
public View getView(int position, View view, ViewGroup viewGroup) {

    // We only create the view if its needed
    if (view == null) {
        view = inflater.inflate(R.layout.child_row, null);

        // Set the click listener for the checkbox
        view.findViewById(R.id.check1).setOnClickListener(this);
    }

    Paper p = (Paper) getItem(position);

    // Set the example text and the state of the checkbox
    CheckBox cb = (CheckBox) view.findViewById(R.id.check1);
    //cb.setChecked(p.isSelected());
    // We tag the data object to retrieve it on the click listener.

    TextView paper = (TextView)view.findViewById(R.id.papername);
    if (paper != null)
        paper.setText(p.getTitle());

    TextView author = (TextView)view.findViewById(R.id.authorname);
    if( author!= null )
        author.setText( p.getAuthor() );

    return view;
}

因此​​,没有识别器对每个复选框。这是一个问题,我可以简单地处理?

So no identificator for each checkbox. Is this an issue I can handle simply?

非常感谢!

推荐答案

在开始http://www.intertech.com/Blog/saving-and-retrieving-android-instance-state双组分-2 /相对=nofollow>片段教程ü可以获取重要的概念。

还ü可以参考随getActivity()的UI组件。findviewbyId(...)或getView()。findviewbyId(...)

跳到有用

at beginning in the page Fragment tutorial U can obtain important concept.
also u can refer to any UI component with getActivity().findviewbyId(...) or getView().findviewbyId(...)
hop to useful

这篇关于保存复选框各国通过在Android的碎片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆