android.widget.LinearLayout无法强制转换为android.widget.TextView(android-studio)

时间:2015-09-19 16:33:08

标签: android android-layout listview android-studio

我试图将数据(来自Intent)粘贴到自定义的ListView上,然后我收到此错误,但是当我使用未经过自定义的ListView时,它正常工作。 我明白当我改变时会出现问题:

ListAdapter theAdapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,timegone);

为:

 ListAdapter theAdapter=new ArrayAdapter<String>(this,R.layout.row_layout,timegone);

但我不明白为什么它不起作用!

下面我添加了导致应用程序崩溃的row_layout.xml文件。

这是如何运作

public class Shifts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

  setContentView(R.layout.shifts);
    Intent MyIntent=getIntent();
    String timepass=MyIntent.getExtras().getString("time");

    ListView thelist=(ListView)findViewById(R.id.MyListView);
   String[] timegone=timepass.split(":");
    ListAdapter theAdapter=new ArrayAdapter<String>(this,**android.R.layout.simple_list_item_1**,timegone);

    thelist.setAdapter(theAdapter);


    }

}

那就是无法运作

public class Shifts extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

  setContentView(R.layout.shifts);
    Intent MyIntent=getIntent();
    String timepass=MyIntent.getExtras().getString("time");

    ListView thelist=(ListView)findViewById(R.id.MyListView);
   String[] timegone=timepass.split(":");
    ListAdapter theAdapter=new ArrayAdapter<String>(this,**R.layout.row_layout**,timegone);

    thelist.setAdapter(theAdapter);


    }
}

这是我在适配器中使用的row_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainScreen"
android:id="@+id/ly"

>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tv1"
    android:textSize="30sp"
    android:textStyle="bold"
    android:padding="15dp"/>

     </LinearLayout>

为了解决这个问题,我该怎么办? 谢谢!

0 个答案:

没有答案