2011-05-23 19 views
5

मेरे आवेदन में मैं सूची दृश्य टेक्स्ट रंग बदलना चाहता हूं। इस मामले में मैं सूची दृश्य के लिए एक्सएमएल फ़ाइल का उपयोग कर रहा हूं। क्या यह संभव है? यदि हां तो उदाहरण दें।सूची बदलें कैसे बदलें टेक्स्ट रंग

आप ArrayAdapter के बजाय डिफ़ॉल्ट android.R.layout.simple_list_item_single_choice पास करने का, सभी ListView वस्तुओं के रंग बदलने के लिए चाहते हैं, तो gender.xml

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

     <ListView 
     android:id="@+id/android:list" 
     android:layout_marginTop="60dip" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:textColor="#000000" 

     /> 

</LinearLayout> 

Egender.java

package com.Elgifto; 

import android.app.ListActivity; 
import android.content.Intent; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.LinearLayout; 
import android.widget.LinearLayout.LayoutParams; 
import android.widget.ListView; 

public class Egender extends ListActivity{ 
    Button b1; 
    ListView lv; 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.gender); 

     // b1=(Button) findViewById(R.id.butt1); 
     b1=new Button(this); 
     b1.setText("Done"); 

     //b1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
     lv=(ListView) findViewById(android.R.id.list); 

     lv.addHeaderView(b1); 

     b1.setOnClickListener(new OnClickListener(){ 
       public void onClick(View v) 
       { 
        // To send a result, simply call setResult() before your 
        // activity is finished. 

        finish(); 
       } 
     }); 

     lv.setAdapter(new ArrayAdapter&lt;String&gt;(this, 
       android.R.layout.simple_list_item_single_choice, GENDER)); 

     lv.setBackgroundColor(Color.BLACK); 
     lv.setItemsCanFocus(false); 
     lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
     lv.setTextFilterEnabled(true); 

    } 

    private static final String[] GENDER = new String[] { 
     "Male","Female" 
    }; 
} 

उत्तर

19

आप पास करना चाहिए कस्टम सूची आइटम एक्सएमएल, जिसमें अलग-अलग टेक्स्टकॉलर विशेषता है।

उदाहरण के लिए, फ़ोल्डर लेआउट के तहत custom_list_item.xml बनाया:,

new ArrayAdapter<String>(this, R.layout.custom_list_item, stringList) 

मुझे मिल गया है सूची थे सभी आइटम लाल कर रहे हैं:

<?xml version="1.0" encoding="utf-8"?> 
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/text1" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 
android:textAppearance="?android:attr/textAppearanceLarge" 
android:gravity="center_vertical" 
android:checkMark="?android:attr/listChoiceIndicatorSingle" 
android:paddingLeft="6dip" 
android:paddingRight="6dip" 
android:textColor="#FF0000" 
/> 

फिर एडाप्टर के लिए यह पारित कर दिया।

+0

सुपर ब्रो !!!!!! – Karthik

+0

नमस्ते मैंने उपरोक्त कोड का उपयोग किया .. लेकिन चयनित आइटम सक्षम नहीं हैं यानी, अनुपात बटन सक्षम नहीं है। उसको कैसे करे – user1835052

संबंधित मुद्दे