Reputation: 31
I want to create a ListView
that contains
Each item has an id and name. Is there any way I can display each item in a rectangular box with border?
Upvotes: 2
Views: 3536
Reputation: 5322
Yes you can, use a SimpleAdapter
to put the Layout you desire for each item in the ListView
:
public SimpleAdapter (Context context, List> data, int resource, String[] from, int[] to)
Parameters context: The context where the View associated with this SimpleAdapter is running data: A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from" resource: Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to" from: A list of column names that will be added to the Map associated with each item. to: The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.
Then set this adapter as the adapter of the ListView
Upvotes: 0
Reputation: 12382
for rectangular border you can make border.xml as below...
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="1dp" android:color="#000000"></stroke>
</shape>
and you can set it into your Textview background...like below...
<TextView
android:id="@+id/Name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17dip"
android:textStyle="bold"
android:background="@layout/border"/>
Upvotes: 1
Reputation: 9507
Yes By following way you can create it.
Your Row Item file for Listview.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/round_shape"
android:orientation="horizontal"
android:padding="10dp" >
<TextView
android:id="@+id/id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/Name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17dip"
android:textStyle="bold" />
</LinearLayout>
round_shape.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="yourstartcolor"
android:startColor="yourendcolor"/>
<corners
android:bottomLeftRadius="27dp"
android:bottomRightRadius="27dp"
android:topLeftRadius="27dp"
android:topRightRadius="27dp" />
</shape>
Upvotes: 1