我想更改listview文本颜色但不改变。此外,我使用了不同的列表样式,但列表中的文本颜色没有变化。帮我解决这个问题 这是代码
public class Line extends Activity
{
List<Map<String, String>> data;
Map<String, String> Line1;
Map<String, String> Line2;
ListView Lines = null;
public void onCreate(final Bundle savedInstanceState)
{
Lines = new ListView(Line.this);
Lines = (ListView) findViewById(R.id.list);
data = new ArrayList<Map<String, String>>();
Line1 = new HashMap<String, String>();
Line1.put("title", "Row | 1" );
Line1.put("status", "");
data.add(Line1);
Line2 = new HashMap<String, String>();
Line2.put("title", "Row | 2" );
Line2.put("status", "");
data.add(Line2);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
void SetStatus(int nLineNo, String sStatusMsg)
{
if(nLineNo == 0)
{
Line1 = new HashMap<String, String>();
Line1.put("title", "Line | 1" );
Line1.put("status", sStatusMsg);
data.set(0, Line1);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
if(nLineNo == 1)
{
Line2 = new HashMap<String, String>();
Line2.put("title", "Line | 2" );
Line2.put("status", sStatusMsg);
data.set(1, Line2);
SimpleAdapter adapter = new SimpleAdapter(this, data, android.R.layout.simple_list_item_2, new String[] {"title", "status"}, new int[] {android.R.id.text1, android.R.id.text2});
Lines.setAdapter(adapter);
}
}
列表视图的xml
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ListView
android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="338dp"
android:padding="10dip"
android:listSelector="#372f89"
style="@drawable/liststyle"
android:textColor="@color/tabDark"
android:background="#fcfbdf"
android:scrollbars="none"
android:cacheColorHint="#ffffff">
<!-- Preview: listitem=@android:layout/simple_list_item_2 -->
</ListView>
</TableRow>
list style xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="6dip"
android:textColor="@color/circlebtn"
android:paddingRight="10dip"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
答案 0 :(得分:1)
目前,您正在传递使用默认android.R.layout.simple_list_item_2
的ListView行的simple_list_item_2
。
将list style xml
(假设由您创建)传递给SimpleAdapter
:
SimpleAdapter adapter = new SimpleAdapter(this, data,
R.layout.<list style xml>, new String[] {"title", "status"},
new int[] {android.R.id.text1, android.R.id.text2});