Is it possible to use a ListView without ListActivity in Mono Android? -
i'm trying implement activity listview among other widgets. if understand correctly can't use listactivity (because shows 1 big listview ist ok me).
i found lot different examples of doing in java this or this or great example.
i've tried in same way doesn't work correctly. i'm curious functionality exists in mono android @ all?
i found 1 example of using listview in mono android this , example describe using listactivity only.
so, layout:
<?xml version="1.0" encoding="utf-8"?> <tablelayout android:id="@+id/widget36" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"> <listview android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"> </listview> </tablelayout>
my oncreate:
protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.createuser); javalist<string> somadata = new javalist<string> { "111", "222", "333" }; listview view = findviewbyid<listview>(resource.id.list); view.adapter = new arrayadapter<string>(this, resource.layout.createuser, somadata); view.textfilterenabled = true; }
i've found solution. had error in line:
view.adapter = new arrayadapter<string>(this, resource.layout.createuser, somadata);
this topic helps me lot.
here further list of layouts can use.
sources of predefined layouts here.
so, there 2 options how fix error , make listview work without listactivity in mono android.
first:
copy/paste layout of standard resource named simple_list_item_1
:
<textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textappearance="?android:attr/textappearancelarge" android:gravity="center_vertical" android:paddingleft="6dip" android:minheight="?android:attr/listpreferreditemheight" />
second (i'm sure it's best way):
use standard resource. in mono android named android.resource.layout.simplelistitem1
updated version of oncreate works perfect:
protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.createuser); javalist<string> somadata = new javalist<string> { "111", "222", "333" }; listview view = findviewbyid<listview>(resource.id.list); view.adapter = new arrayadapter<string>(this, android.resource.layout.simplelistitem1, somadata); }
Comments
Post a Comment