Custom Layout not detecting in mainActivity class?

Question!

I am a beginner at android.

I am using Android Studio 1.0. I am trying to make a custom layout for listView. I created custom layout files in the res/layout named row_layout. xml for layout is this:

<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 to implement that custom layout in the MainActivity class is:

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

But activity class doesn't detect this custom layout and shows the error below while building.

enter image description here



Answers

R.layout denotes the resources which are provided by your application. All the variables, resource files (drawable, string, layout etc) which are defined by your application can be accessed by R.

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

But android.R denotes the resources of your android SDK. all the resources which are not defined by you but are defined by android SDK will be available to you if you use android.R

In your code, you are using your own layout so replace android.R.layout with R.layout



It should be:

ListAdapter theAdapter = new ArrayAdapter
By : pre_03


This video can help you solving your question :)
By: admin