如何获得List <list <string>&gt;用这个关键字?

时间:2017-02-09 13:19:24

标签: android list this bundle

我有片段,我在List中获取字符串并将其作为 Bundle 发送到活动。例如,我得到一个字符串,然后通过以下方式将其发送到活动:

s = pd.Series(index=[2,4,5,6], data=[None, None, 2, None])

现在应该是my(1)和(2)才能访问latest_list并将其传递给bundle?

1 个答案:

答案 0 :(得分:1)

1)你不能在这里使用this。将其设置为方法上方的私有权限,如下所示:

public class ViewPagerAdapter extends FragmentStatePagerAdapter
{
    private CharSequence contentTitle[];
    private List<List<String>> latestList; // This let's you use latestList outside of this ViewPagerAdapter class.
    public ViewPagerAdapter(Response<album> response)
    {
        List<String> listcontentTitle = new ArrayList<>();
        List<List<String>> latest_list = new ArrayList<>();      
        List<String> latestdate = new ArrayList<>();
        List<String> latestcomment = new ArrayList<>();
        for (int i = 0; i < 5; i++) 
        {
            listcontentTitle.add(String.valueOf(response.body().getcontent().get(i).getcontentTitle()));
            latestdate.add(String.valueOf(response.body().getcontent().get(i).getcontentdate()));
            latestcomment.add(String.valueOf(response.body().getcontent().get(i).getcontentcmnt()));
        }
        latest_list.add(latestdate);
        latest_list.add(latestcomment);
        contentTitle = listcontentTitle.toArray(new CharSequence[listcontentTitle.size()]);
        lastestList = lastest_list;
    }
    public List<List<String>> getLatestList(){
        return latestList;
    }

您现在可以在另一个类中使用latestList

ViewPageAdapter viewpage = new ViewPageAdapter(response);
List<List<String>> latest_list = viewpage.getLatestList();

要使用捆绑包传递列表,请查看以下答案:https://stackoverflow.com/a/28197436/4561008

您需要在ViewPageAdapter声明中使用implements Parcelable