我在android中动态创建了一个textview。当我单击文本视图时,颜色从白色变为橙色,但我想要的是当我单击另一个文本视图时,另一个已更改为橙色的文本视图将变回白色。这是创建文本视图的代码:
for (int i = 1; i <= n; i++) {
final TextView mPageNumber = new TextView(getActivity());
mPageNumber.setText("" + i);
mPageNumber.setId(Integer.parseInt(String.valueOf(i)));
mPageNumber.setTextColor(getResources().getColor(R.color.colorWhite));
mPageNumber.setPadding(60,30,60,30);
final int id_ = mPageNumber.getId();
LinearLayout layout = (LinearLayout) getView().findViewById(R.id.pagination);
layout.setBackgroundResource(R.color.colorPrimary);
layout.addView(mPageNumber);
OnClickListener
mPageNumber.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (toastMessage!= null) {
toastMessage.cancel();
}
toastMessage = Toast.makeText(getActivity().getApplicationContext(), "Button with id =" + id_ +
" is clicked",Toast.LENGTH_SHORT);
current = id_;
toastMessage.show(); mPageNumber.setTextColor(getResources().getColor(R.color.colorOrange));