我有一个列表视图。我想区分标题和描述。我想显示标题一种颜色,而描述是另一种颜色。我怎样才能做到这一点?我有以下用于创建列表视图的代码。
活动:
public class Lisearch extends Activity {
private ListView lv;
private EditText et;
private String listview_array[] = {"ONE:\n one is the first letter"};
private ArrayList<String> array_sort= new ArrayList<String>();
int textlength=0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lisearch);
TextView tv=(TextView)findViewById(R.id.text);
lv = (ListView) findViewById(R.id.ListView01);
et = (EditText) findViewById(R.id.EditText01);
//lv.setAdapter(new ArrayAdapter<String>(this,
//R.layout.activity_lisearch, listview_array));
et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
// Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s,
int start, int count, int after)
{
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s,
int start, int before, int count)
{
textlength = et.getText().length();
array_sort.clear();
for (int i = 0; i < listview_array.length; i++)
{
if (textlength <= listview_array[i].length())
{
if(et.getText().toString().equalsIgnoreCase(
(String)
listview_array[i].subSequence(0,
textlength)))
{
array_sort.add(listview_array[i]);
}
}
}
lv.setAdapter(new ArrayAdapter<String>
(Lisearch.this,
R.layout.list,R.id.text, array_sort));
搜索.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/aa"
>
<EditText android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Search"
android:padding="5dp">
</EditText>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@drawable/list_selector"
android:layout_weight="1"
>
</ListView>
</LinearLayout>
列表.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dp"
android:textSize="15sp"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textColor="#FF4444"
android:textStyle="bold"
android:layout_marginLeft="10dp"
/>