2
我的行列表視圖是在它自己的xml文件中定義的。它包含一些文字瀏覽。如何根據行狀態(選中,正常,...)更改列表視圖行中textview的文本顏色?
如何根據行的狀態(選定,聚焦,正常...)設置這些textviews的文本顏色?
我的行列表視圖是在它自己的xml文件中定義的。它包含一些文字瀏覽。如何根據行狀態(選中,正常,...)更改列表視圖行中textview的文本顏色?
如何根據行的狀態(選定,聚焦,正常...)設置這些textviews的文本顏色?
您必須爲每一行使用setOnFocusChangedListener()。並訪問您的textViews,並更改文字顏色。
row.setOnFocusChangedListener(focuschangedListener);
private onFocusChangedListener focustchangedListener = new onFocusChangedListener(
@Override
public void onFocusChange(View row, boolean arg1) {
//get access to textviews using row.findViewById()
if (arg1) {
// view is on focus, change the textcolor
} else {
// view lost focus, change the text colors to normal.
}
}
);
如果你在你的代碼列表視圖設置適配器然後覆蓋getView適配器的是這樣的:
adapter = new ArrayAdapter<String>(YourActivity.this , R.layout.liststylelayout)
{
@Override
public View getView(int position, View convertView,ViewGroup parent)
{
View v = super.getView(position, convertView, parent);
//v is parent view which has your textview as child
TextView tv1 =(TextView)v.findViewById(R.id.movielistitemstrings);
//get your textview like this
tv1.setTextColor(Color.parseColor("#FF8000"));
//do your operations on textview
}
};