我在对话框中有一个ListView&我想在ListView中将项目TextColor设置为Brown,因此我将此适配器用于我的ListView:
public class RankingListAdapter extends BaseAdapter {
private Context context;
private ArrayList<RankingItem> RankingItems;
int Po;
public RankingListAdapter(Context context, ArrayList<RankingItem> navDrawerItems, int p) {
this.context = context;
this.RankingItems = navDrawerItems;
this.Po = p;
}
@Override
public int getCount() {
return RankingItems.size();
}
@Override
public Object getItem(int position) {
return RankingItems.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.ranking_list_item, null);
}
TextView TVRank = (TextView) convertView.findViewById(R.id.TVRank);
TextView TVUser = (TextView) convertView.findViewById(R.id.TVUser);
TextView TVLVL = (TextView) convertView.findViewById(R.id.TVLVL);
TextView TVScore = (TextView) convertView.findViewById(R.id.TVScore);
Typeface TEng = Typeface.createFromAsset(context.getAssets(), "fonts/English.ttf");
Typeface TNum = Typeface.createFromAsset(context.getAssets(), "fonts/Nums.ttf");
TVRank.setText(RankingItems.get(position).getRank());
TVRank.setTypeface(TNum);
TVUser.setText(RankingItems.get(position).getUsername());
TVUser.setTypeface(TEng);
TVLVL.setText(RankingItems.get(position).getLVL());
TVLVL.setTypeface(TNum);
TVScore.setText(RankingItems.get(position).getScore());
TVScore.setTypeface(TNum);
if (position == Po) {
TVRank.setTextColor(Color.parseColor("#b38620"));
TVUser.setTextColor(Color.parseColor("#b38620"));
TVLVL.setTextColor(Color.parseColor("#b38620"));
TVScore.setTextColor(Color.parseColor("#b38620"));
}
return convertView;
}
}
但是当我运行我的应用程序时,我看到了这个: enter image description here
问题是什么?
答案 0 :(得分:1)
也为颜色写
if (position == Po) {
TVRank.setTextColor(Color.parseColor("#b38620"));
TVUser.setTextColor(Color.parseColor("#b38620"));
TVLVL.setTextColor(Color.parseColor("#b38620"));
TVScore.setTextColor(Color.parseColor("#b38620"));
}
else
{
//set default color of your texts.
TVRank.setTextColor(Color.BLACK);
TVUser.setTextColor(Color.BLACK);
TVLVL.setTextColor(Color.BLACK);
TVScore.setTextColor(Color.BLACK);
}
答案 1 :(得分:0)
设置else
条件,并在else
条件下写下要设置的颜色。试试这个
if (position == Po) {
TVRank.setTextColor(Color.parseColor("#b38620"));
TVUser.setTextColor(Color.parseColor("#b38620"));
TVLVL.setTextColor(Color.parseColor("#b38620"));
TVScore.setTextColor(Color.parseColor("#b38620"));
}else{
//set your required color to the required textView here
}