2012-05-17 50 views
6

私は白い背景を持っていますが、このレイアウトでは、テキストの色も白で、私は白い背景を設定することができますので、私は白いテキストを見ることができるので、私は彼女の赤い背景を使用するように強制されていることがわかります)。テキストの色を変更する

public class QueueListActivity extends ListActivity { 
// LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS 
ArrayList<String> listItems = new ArrayList<String>(); 
String newtext; 
String listFiles; 
// DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW 
ArrayAdapter<String> adapter; 

// RECORDING HOW MUCH TIMES BUTTON WAS CLICKED 
int clickCounter = 0; 

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


@Override 
public void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.queuelistactivity); 
    Bundle extras1 = getIntent().getExtras(); 
    listFiles=GetFiles(); 

    StringTokenizer tokonizer1 = new StringTokenizer(listFiles,";"); 
    while(tokonizer1.hasMoreElements()){ 
     Log.i("verif","0"); 
     listItems.add(tokonizer1.nextToken());} 
      initializeListItems(); 



    if (extras1 != null) { 
     newtext = extras1.getString("newitem"); 
     listItems.add(newtext); 
     adapter.notifyDataSetChanged(); 
     getListView().setItemChecked(listItems.size() - 1, false); 

    } 




} 



// METHOD WHICH WILL HANDLE DYNAMIC INSERTION 
public void addItems(View v) { 

    Intent intent = new Intent(QueueListActivity.this, AjouterFiles.class);  
    QueueListActivity.this.startActivity(intent); 


    /* 
    listItems.add(userName); 
    adapter.notifyDataSetChanged(); 
    getListView().setItemChecked(listItems.size() - 1, false);*/ 


} 

public void deleteItems(View v) { 
    String toDelete = ""; 
    SparseBooleanArray sp = getListView().getCheckedItemPositions(); 

    for (int i = 0; i < sp.size(); i++) { 
     toDelete += ";" + sp.get(i); 
     if (sp.get(i)) { 
      listItems.remove(i); 
     } 

    } 
    adapter.notifyDataSetChanged(); 
    Toast.makeText(getApplicationContext(), toDelete, Toast.LENGTH_LONG).show(); 
    initializeListItems(); 
} 

private void initializeListItems() { 
    adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_multiple_choice, listItems); 
    setListAdapter(adapter); 
    ListView lv = getListView(); 
    lv.setCacheColorHint(Color.rgb(0, 0, 0)); 
    lv.setBackgroundColor(Color.rgb(178, 34, 34)); 


    for (int i = 0; i < lv.getCount(); i++) { 
     lv.setItemChecked(i, false); 
    } 
} 
+0

に従ってください。..カスタムリストビューを試すことができますが、ここで – Abhinai

答えて

11

ベストトリックあなたはandroid.R.layout.simple_list_item_multiple_choiceからコンテンツレイアウトファイルをコピーし、独自のレイアウトを作成している(my_list_view xmlファイルを編集してテキストの色を変更してください。

アダプター=新しいArr ayAdapter(this、my_list_view、listItems);

編集このファイルをmy_list_viewとして保存します。

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical" 
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
    android:paddingLeft="6dip" 
    android:paddingRight="6dip" 
    android:backdround="#FFFFFF" //white background 
    android:textColor="#000000" //black color text 
/> 
+0

どのようにすればandroid.R.layout.simple_list_item_multiple_choiceを見つけることができますか? –

+1

あなたはandroid.R.layout.simple_list_item_multiple_choiceでCtrl + mousehoverできますが、そのコードをペーストしました – vnshetty

+0

エラー:エラー:文字列型は許可されません(値 'match_parent'の 'layout_width')。 –

1

あなたはXMLレイアウトでそれを設定することができます。

<TextView 
... 
... 
android:textColor="#FF0000" > 
</TextView> 

またはプログラム:

textview.setTextColor(Color.RED); 
//textview must be defined in your class 
+1

ウルxmlファイルをコピーします! –

0

カスタムアダプターを書く方が良いです。

代替ではなく、良いsoltuonこれは、同じandroid.R.layout.simple_list_item_multiple_choiceレイアウトであるandroid.R.layout.simple_list_item_multiple_choice

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:gravity="center_vertical" 
    android:checkMark="?android:attr/listChoiceIndicatorMultiple" 
    android:paddingLeft="6dip" 
    android:paddingRight="6dip" 


    android:textColor= Color.Red  //please correct the syntax 
/> 

のこのレイアウトのxml inspaceを使用しているが、あなたは今、あなたのレイアウトで同じことを行っていますそれに変更を加えるために同じIDであなたは私がのTextViewを持っていない見ることができれば

+0

私は新しいxmlファイルを作成し、これを何にコピーしますか? –

+0

あなたの名前のレイアウトで新しいxmlを作成し、このコードをそのxmlに貼り付け、あなたのアダプターのandroid.R.layout.simple_list_item_multiple_choiceの代わりにこのxmlを使用してください。あらかじめ定義されているように、ArrayAdapterは取得ビューでID「text1」を探し、取得したIDをXMLで取得します。 –

+0

私は今これでエラーが発生しました:エラー:( 'layout_width'で値 'match_parent'で)エラー:文字列型が許可されていません。 –

0
<TextView 
     android:id="@+id/text_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Name" 
     android:textColor="@color/white" 
     android:textSize="11dp" 
/> 
4
android:textColor="@android:color/white" 
関連する問題