Android.view.View错误

时间:2015-07-22 21:37:04

标签: java android arrays view return

我明白了:

   import android.os.Bundle;
   import android.support.v4.app.Fragment;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.widget.TextView;

...

   View android[]  = new View[6];
    android[0] = inflater.inflate(R.layout.asd_frag, container, false);
    ((TextView) android[0].findViewById(R.id.textViewAsd01)).setText("Asd");
    ((TextView) android[0].findViewById(R.id.game_asd_name_one)).setText("hi");

和这个

android[1] = inflater.inflate(R.layout.qwe_frag, container, false);
((TextView) android[1].findViewById(R.id.textViewQwe01)).setText("qwe");
((TextView) android[1].findViewById(R.id.game_Qwe_name_two)).setText("bye");
return android;

当我尝试返回此数组时,我收到一条奇怪的消息:

*Incompatible types

Required android.view.View

Found android.view.View[]*

我基本上只想发布我的数组。

所以我点击Android Studio提示,我得到了这个奇怪的错误, enter image description here

2 个答案:

答案 0 :(得分:1)

在定义变量时,请尝试View[] android而不是View android[]

使它成为

View[] android  = new View[6];

答案 1 :(得分:0)

androidView的数组。

*Incompatible types

Required android.view.View

Found android.view.View[]*

你正在使用的函数有一个返回类型android.view.View,而不是一个Views(android.view.View[])数组。

如果这不是必须与定义匹配的重写函数,则可以将函数定义更改为android.view.View[]

否则,您需要返回android元素,即android[0]