Custom layout not showing up in mainActivity class?

I am new to android.

I use Android Studio 1.0. I'm trying to do custom layoutfor listView. I created custom layout files in res/layout named row_layout. xml for layout:

<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"
    tools:context=".MainActivity"
    android:orientation="vertical">

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

Code for implementing this custom layout in the MainActivity class:

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

But the activity class does not detect this custom layout and shows an error below when creating.

enter image description here

+4
source share
3 answers

R.layout , . , (drawable, string, layout ..), , R.

R.layout.*, r.drawable.*, R.id.*, R.color.* etc

android.R SDK Android. , , SDK Android, , android.R

, android.R.layout R.layout

+2

android.R. R., R.* , android.R.* , Android SDK. (R.* your.package.R.*)

, .

+3

:

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

android.R refers to those resources previously built into the sroid sroid.

Since you have defined your own layout for representing a custom list, you must use the R file generated in your project.

+2
source

Source: https://habr.com/ru/post/1569110/


All Articles