I have done my custom ListView, the xml was following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="@+id/list" android:layout_width="1px" android:layout_height="1px" android:layout_weight="1"></ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/img" android:layout_width="26px" android:layout_height="30px" />
<TextView android:id="@+id/title" android:layout_width="248dp" android:layout_height="wrap_content" android:textStyle="bold" android:paddingLeft="6dp" android:textSize="20sp" />
<ImageButton android:id="@+id/cat_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:layout_marginRight="2dp" />
<ImageButton android:id="@+id/act_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" />
</LinearLayout>
</LinearLayout>
‘
And code is
public class MyListActivity extends ListActivity
{
protected void onCreate(Bundle savedInstanceState)
{
Log.i("MyApp", "ON List create......");
super.onCreate(savedInstanceState);
List<BeanObj> list=...//Do something to fill list
setListAdapter(new MyListViewAdapter(context, R.layout.item_view, list));
}
public class MyListViewAdapter extends ArrayAdapter<List<BeanObj>>
{
private List<BeanObj> hList=null;
public MyListViewAdapter(Context context, int textViewResourceId, List hList)
{
super(context, textViewResourceId, hList);
this.hList=hList;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final BeanObj bean=this.hList.get(position);
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.item_view, parent, false);
// Do something to fill ListView
return row;
}
}
}
I did try to add a button on it, but I got each button on each row of list view…
What can I do on xml to add floating button over my custom list view ?
Or, I caeate another xml layout file below:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="left|top">
<Button android:id="@+id/btnLogout" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonLogout" />
<View android:layout_width="75dp" android:layout_height="40dp" />
<Button android:id="@+id/btnList" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonList" />
<Button android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonSearch" />
</LinearLayout>
How did I to use it via addHeaderView or addFooterView method ?
You need to add the header and the footer before setting the ListAdapter for the list. From the docs:
Also inflating your views in the getView method is not the most optimum way. You need to use a static class for storing the reference to the inflated view. Check out this talk to correctly set up the views.