【发布时间】:2014-10-14 07:14:34
【问题描述】:
我在我的应用程序中使用 Edittexts。但无法在运行时设置它们的背景颜色。如果我做错了什么,请提出建议。
我已经采用了三个编辑文本,它们应该根据 do while 循环中使用的 if 编码改变它们的颜色。请检查并尽快回复。提前致谢。
这是我的代码。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
List<Map<String,String>> list = new ArrayList<Map<String,String >>();
EditText ed1 = (EditText) findViewById(R.id.name);
EditText ed2 = (EditText) findViewById(R.id.age);
EditText ed3 = (EditText) findViewById(R.id.date);
Map<String,String> map = new HashMap<String, String>();
int i = 2;
EmpDatabase empClick = new EmpDatabase(getApplicationContext());
Cursor cursor = empClick.getDetails();
if(cursor.moveToFirst()){
do{
i= i+1;
if(i % 2 == 0)
{
// here is something wrong
ed1.setBackgroundColor(Color.BLUE);
ed2.setBackgroundColor(Color.BLUE);
ed3.setBackgroundColor(Color.BLUE);
}
else
{
// here is something wrong
ed1.setBackgroundColor(Color.CYAN);
ed2.setBackgroundColor(Color.CYAN);
ed3.setBackgroundColor(Color.CYAN);
}
map = new HashMap<String, String>();
String name = cursor.getString(cursor.getColumnIndex("name"));
String age = cursor.getString(cursor.getColumnIndex("age"));
String time = cursor.getString(cursor.getColumnIndex("time"));
map.put("name",name);
map.put("age",age);
map.put("time", time);
list.add(map);
}while(cursor.moveToNext());
cursor.close();
}
SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.text_view, new String [] {"name", "age", "time"}, new int[] {R.id.name,R.id.age, R.id.date});
setListAdapter(adapter);
}
【问题讨论】:
-
hii 只使用颜色的 setbackground 和 setcontent 视图
-
检查光标移动到第一个。如果条件不满足,可能是这样。
-
没有光标问题..我取了一个整数i来改变颜色。
-
我也试过 setbackground .. 但没用。
-
试试这个
int j = i%2;并使用j.equal("0");
标签: android android-edittext background-color