0

Im Trying To paste data(from an Intent) on a customized ListView ,and then I get this error,but when I did it with an uncustomized ListView it worked properly. I understood that the problem occurs when I change :

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

to:

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

But I dont get why it doesnt work!

Here below I added the row_layout.xml file which Causes the app crash.

Thats how it works :

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);


    }

}

And thats how it doesnt work:

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);


    }
}

This is the row_layout.xml that im using in the adapter

<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>

What should I do in order to fix this ? Thank you!

2
  • you need to create custom adapter for your custom row... Commented Sep 19, 2015 at 17:02
  • The TextView has to have ID @android:id/text1. Or remove the LinearLayout, because it's useless, it has just one child element. Commented Sep 19, 2015 at 20:52

1 Answer 1

1

You need to create custom adapter if you want custom layout of list row..

here you can see the example.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.