Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curved border for list view

Tags:

android

I am newbie to android and java, i need to create a simple application in android. I have a Activity page in this activity. Here is my activity page

package com.tkcmu.dev;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class tkcmu extends Activity {
    private ListView lv1;

    @Override
        public void onCreate(Bundle icicle)
        {
        super.onCreate(icicle);
        setContentView(R.layout.main);


        ArrayList<String> listItems = new ArrayList<String>();

        try {
            URL recentUrl = new URL(
                    "To some link");
            URLConnection tc = recentUrl.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

            String line;
            while ((line = in.readLine()) != null) {
                JSONArray ja = new JSONArray(line);

                for (int i = 0; i < ja.length(); i++) {
                    JSONObject jo = (JSONObject) ja.get(i);
                    listItems.add(jo.getString("content"));
                }
            }

    }catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }catch (IOException e) {
                e.printStackTrace();

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        lv1=(ListView)findViewById(R.id.ListView01);
        // By using setAdpater method in listview we an add string array in list.
        lv1.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , listItems));
        }
}

and my main.xml is like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ListView
        android:id="@+id/ListView01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_marginLeft="10sp"
        android:layout_marginRight="10sp"
        android:layout_marginTop="10sp"
        android:layout_weight="1"
        android:background="@drawable/customshape"
        android:cacheColorHint="#FFFFFF"
        android:clickable="true"
        android:clipToPadding="true"
        android:dividerHeight="1px"
        android:drawSelectorOnTop="false"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:footerDividersEnabled="true"
        android:headerDividersEnabled="true"
        android:longClickable="true" />
</LinearLayout>

and also i have an customshape.xml in drawable which is

 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp" />
</shape>

I got the result with the entire custom list section get curved but i want to get each row with a curved background. I have posted my entire code here(exclude AndroidManifest.xml) so this will be appreciated if anybody tell me exactly what changes i need to in this code. Any body have an idea about how to implement it.

like image 321
user359187 Avatar asked Feb 25 '23 08:02

user359187


1 Answers

add

 android:background="@drawable/customshape" 

to the root view of the listview row.xml file rather than applying it to the listview

like image 127
user8601021 Avatar answered Mar 03 '23 23:03

user8601021