multiline listview need help figuring this out
I have really tried hard for a week trying to figure out how to make multiline text in a listview. but i simply cant figure out what i am doing wrong.
tells me i need a listview named android.R.id.list but i can find anywhere in the code where i have referred to such a list.
anyone who can help would be appreciated.
Ty for your time and best regards,
Mark
i have created a list view
Code:
<ListView
android:id="@+id/listview2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="@+id/AddsBannerHere"
android:layout_alignParentLeft="true"
android:layout_below="@+id/NameOfList"
android:layout_toLeftOf="@+id/NameOfItem"
android:layout_marginLeft="5dp" >
</ListView>
and made a textview to put in the text
Code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/line_a"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/line_b"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/line_c"/>
</LinearLayout>
and wrote this for class
Code:
public class CreateFirst extends ListActivity {
private AdView adView;
private SimpleAdapter sa;
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
public void Add_New_Item() {
HashMap<String,String> item;
EditText nameofitem = (EditText) findViewById(R.id.NameOfItem);
String stringnameofitem = nameofitem.getText().toString();
item = new HashMap<String,String>();
item.put("line1", stringnameofitem);
EditText nrofitem = (EditText) findViewById(R.id.NrOfItem);
EditText weightofitem = (EditText) findViewById(R.id.Weight_Liter);
String stringnrofitem = nrofitem.getText().toString() + " " + weightofitem.getText().toString();
item.put("line2", stringnrofitem);
EditText valueofitem = (EditText) findViewById(R.id.Value_Of_Item);
String stringvalueofitem = valueofitem.getText().toString();
item.put("line3", stringvalueofitem);
list.add( item );
sa = new SimpleAdapter(this, list,
R.layout.activity_multi_lines,
new String[] {"line1", "line2","line3"},
new int[]{R.id.line_a, R.id.line_b, R.id.line_c});
setListAdapter(sa);
}
when i try to open the activity i get
Code:
10-22 18:53:33.053: D/gralloc_goldfish(840): Emulator without GPU emulation detected.
10-22 18:53:34.493: D/AndroidRuntime(840): Shutting down VM
10-22 18:53:34.493: W/dalvikvm(840): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-22 18:53:34.523: E/AndroidRuntime(840): FATAL EXCEPTION: main
10-22 18:53:34.523: E/AndroidRuntime(840): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.shopping.list.by.mp/com.shopping.list.by.mp.CreateFirst}:
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread.access$600(ActivityThread.java:123)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.os.Handler.dispatchMessage(Handler.java:99)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.os.Looper.loop(Looper.java:137)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread.main(ActivityThread.java:4424)
10-22 18:53:34.523: E/AndroidRuntime(840): at java.lang.reflect.Method.invokeNative(Native Method)
10-22 18:53:34.523: E/AndroidRuntime(840): at java.lang.reflect.Method.invoke(Method.java:511)
10-22 18:53:34.523: E/AndroidRuntime(840): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-22 18:53:34.523: E/AndroidRuntime(840): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-22 18:53:34.523: E/AndroidRuntime(840): at dalvik.system.NativeStart.main(Native Method)
10-22 18:53:34.523: E/AndroidRuntime(840): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
10-22 18:53:34.523: E/AndroidRuntime(840): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.Activity.setContentView(Activity.java:1835)
10-22 18:53:34.523: E/AndroidRuntime(840): at com.shopping.list.by.mp.CreateFirst.onCreate(CreateFirst.java:34)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.Activity.performCreate(Activity.java:4465)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-22 18:53:34.523: E/AndroidRuntime(840): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
10-22 18:53:34.523: E/AndroidRuntime(840): ... 11 more