理解代码的问题

时间:2017-12-25 17:58:57

标签: java android

当我从Udacity上可用的课程学习Android应用程序开发时...对于用户界面和用户输入一切都很好并且能够理解,但是当涉及到像ArrayList和数组适配器的打印这样的主题时,我真的很难理解所有那些东西。例如,我不明白代码中发生了什么,如:

package inffrd;

public class Q001 
{
    public static void removeduplicate(String input)
    {
        //convert the string to array by splitting it in words where space comes
        String[] words=input.split(" ");
        //put a for loop for outer comparison where words will start from "i" string
        for(int i=0;i<words.length;i++)
        {
            //check if already duplicate word is replaced with null
            if(words[i]!=null)
            {
                //put a for loop to compare outer words at i with inner word at j
                for(int j =i+1;j<words.length;j++)
                {
                    //if there is any duplicate word then make is Null
                    if(words[i].equals(words[j]))
                    {
                        words[j]=null;
                    }
                }
            }
        }
        //Print the output string where duplicate has been replaced with null
        for(int k=0;k<words.length;k++)
        {
            //check if word is a null then don't print it
            if(words[k]!=null)
            {
                System.out.print(words[k]+" ");
            }
        }
    }

    public static void main(String[] args) 
    {
        String s1="i am dinesh i am kumar";
        Q001.removeduplicate(s1);
    }
}

任何人都能说出不理解这些事情的根本原因是什么,以便我可以在那部分工作?

2 个答案:

答案 0 :(得分:1)

您应该了解适配器的工作原理。像这样的教程http://www.androidtutorialshub.com/android-recyclerview-tutorial/将帮助您了解如何编写自定义适配器(本教程适用于RecyclerView,但适配器的主要思想是相同的)。在了解适配器如何工作之后,您会注意到ArrayAdapter只是创建简单适配器的便捷方式。

答案 1 :(得分:0)

列表视图在Android应用程序的列表表单中显示整个数据。 findviewbyid用于使用项目的xml文件中的id访问数据。