-2

I am trying to change my font(color and size) and the back ground on my ListView. I want to change it with code lines not on xml. my list view looks like: the xml: please answer to my ask. Thankyou

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/listview"
        style="@style/styleName"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="10dp" >
    </ListView>
</LinearLayout>

code is:

package ir.Rubin.SecondTerm;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ActivityListView extends Activity {
    ListView mListView;
    List<String> mList = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_listview);
        // findView
        mListView = (ListView) findViewById(R.id.listview);
        // for adding items
        for (int i = 0; i < 200; i++) {
            mList.add("Android Class" + i);
        }
        // Creating Data
        ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mList);
        // Setting Adapter
        mListView.setAdapter(mAdapter);
    }
}
m.asadi
  • 47
  • 2
  • 13

2 Answers2

0

Check the properties present in the listview component , the link below(link one). The Android documentation is extensive and very complete . She is the great friends of the developers. If you want examples, take a look at Vogela(link two) site. There are good tutorials there. But always give priority to official documentation .

hug =]

I hope this helps

Links:

1 -http://developer.android.com/reference/android/widget/ListView.html

2 -http://www.vogella.com/

-1
  <ListView>
    android:id="@+id/listview"
    style="@style/styleName"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:dividerHeight="10dp" 
    android:textsize="#sp"
    android:textColor="[hex color code here]"
</ListView>

this should work