How to Add button in listview

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to Add button in listview

Postby ashish » Mon Jun 01, 2009 5:51 pm

Hello everybody,

Actually i want to create one listview in which i want to have one button along with listitem.
problem is that whenever i do this..i am unable to select the listitem.

Does anybody know how to achieve this????

Thanks you.
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Top

Postby divestoclimb » Tue Jun 02, 2009 2:21 am

Have you tried calling setItemsCanFocus?
See http://developer.android.com/reference/ ... tView.html
divestoclimb
Developer
Developer
 
Posts: 33
Joined: Mon May 11, 2009 7:46 pm

Postby ashish » Tue Jun 02, 2009 8:59 am

Thanks dives, but for me it doesn't work...i am placing my source code..


dashboard=(ListView)findViewById(R.id.dashboard);


dashboard.setOnItemClickListener(this);

dashboard.setItemsCanFocus(true);

dashboard.setSelection(0);
dashboard.setDividerHeight(2);

ArrayAdapter<Object> dashboard_adapter = new ArrayAdapter<Object>(this, R.layout.dashboard_item_layout,R.id.dashboard_item_textview,category_info);

dashboard.setAdapter(dashboard_adapter);


ListView layout
_____________________
<?xml version="1.0" encoding="utf-8"?>
<!--
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="@drawable/maintheme">

<ImageView
android:id="@+id/icon"
android:layout_height="50px" android:layout_width="fill_parent"/>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_dashboard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/icon" android:text="My Dashboard" android:layout_centerHorizontal="true" android:textSize="20px" android:textColor="@color/dark_black"/>

<ListView android:id="@+id/dashboard"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000" android:drawingCacheQuality="high" android:smoothScrollbar="true" android:layout_marginBottom="20px" android:layout_marginTop="100px" android:clickable="true" android:focusable="true"/>




</RelativeLayout>


ListView Item Layout
____________________________

<?xml version="1.0" encoding="utf-8"?>
<!--
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dashboard_item_textview"
android:layout_width="fill_parent"
android:textAppearance="?android:attr/textAppearanceSmall"
android:minHeight="?android:attr/listPreferredItemHeight" android:text="hello" android:layout_height="40px" android:textColor="@color/dark_black" android:layout_marginRight="50px"/>

<ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/plus" android:layout_centerHorizontal="true" android:layout_alignParentRight="true" android:id="@+id/edit_category" android:focusable="true" android:clickable="true"></ImageButton>


</RelativeLayout>



I am using ImageButton with my listview item.
and one thing more how to handle click event of button because i am getting a NULL pointer exception.

Thank You.
ashish
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Fri Feb 20, 2009 8:09 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 9 guests