What should i write in parameter of a method in android

This question already has an answer here:

  • What is 'Context' on Android? 29 answers

  • If you are using your method in any activity or service, then no need to pass context,because they have their own context. Just use this (context) wherever you need. so your code will look like:

    void showhistory()
    {
        TextView historyword[] = new TextView[rs.getColumnCount()];
        for(int i=0;i<rs.getColumnCout();i++)
            historyword[i] = new TextView(this);
    }
    

    创建TextView需要使用Context作为上下文

    void showhistory(Context context)
    {
        TextView historyword[] = new TextView[rs.getColumnCount()];
        for(int i=0;i<rs.getColumnCout();i++)
            historyword[i] = new TextView(context);
    }
    
    链接地址: http://www.djcxy.com/p/91374.html

    上一篇: 所有关于上下文:如何使用上下文?

    下一篇: 我应该在android中的一个方法的参数写什么