java如何在for循环中仅为一个字符串更改Textcolor?
一个基本的问题->;因为我找不到答案因为很多天。。。
如果我有一个for loop
(10次),每个输出都是不同的string
。我怎样才能使一个特定的String-output
颜色
for(int i=0; i< posts.length();i++ ) {
JSONObject post = posts.optJSONObject(i);
this.title = post.optString("title");
blogTitles[i] = title;
}
当然,我可以按代码对特定的blogtitles[i]
进行排序
title.toLowerCase().contains("neune")
但是如果我尝试给它新的layout
,他layout
用于所有(10x)输出
有人能帮忙吗
Thx的答案现在我改为
JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
但仍然所有的输出都是黑色的,并且是“安卓.R.layout.simple_list_item_1”的布局
完整代码
for(int i=0; i< posts.length();i++ ) {
JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
arrayAdapter1 = new ArrayAdapter(MainActivity.this, R.layout.mytextview, blogTitles1);
arrayAdapter2 = new ArrayAdapter(MainActivity.this, 安卓.R.layout.simple_list_item_1, blogTitles2);
if (title.toLowerCase().contains("neune") && title.contains(this.id.toLowerCase())) { //ean nicht neu (!kontrolliert!)
// listView.setTheme(R.layout.mytextview);
listView.setAdapter(arrayAdapter1);
String title2= title.replace("neune*", "");
String title3 = title2.replace(this.id + ",", "-eigene Bewertung");
blogTitles1[i] = title3;
bewertungseingabe.setVisibility(View.VISIBLE);
bewertungsueberschrift.setVisibility(View.VISIBLE);
bewertbutton.setVisibility(View.VISIBLE);
editBtn.setVisibility(View.VISIBLE);
}
if (title.toLowerCase().contains("neune") ) {
listView.setAdapter(arrayAdapter2);
String title2= title.replace("neune*", "error!!!!");
String title3 = title2.replace(this.id + ",", "*");
blogTitles2[i] = title3;
}
if (title.toLowerCase().contains("neuja")&& title.contains(this.id.toLowerCase())) { //ean neu (!noch nicht kontrolliert!)
String title2= title.replace("neuja*", "");
String title3 = title2.replace(this.id + ",", "-eigene Bewertung");
blogTitles1[i] = title3;
}
if (title.toLowerCase().contains("neuja") ) {
blogTitles2[i] = "Dieser Artikel ist in Ordnung!";
}
if (title.toLowerCase().contains("ganz")) { //ean neu (!noch nicht kontrolliert!)
blogTitles2[i] = "Du hast uns so eben eine neue EAN mitgeteilt" +
"füge eine Bezeichnung und Bewertung hinzu, wenn du magst...";
// zaehler[i]=blogTitles[i];
}
}
只使用第二种布局。。。。我猜这是因为“title.toLowerCase().contains(“neune”)&title.contains(this.id.toLowerCase())”是真的,“title.toLowerCase().contains(“neune”)”是真的。。。。它“必须”是这样的,因为每个(i)输出都应该被评估
# 1 楼答案
编辑:
字符串getStr
# 2 楼答案
解析
Json
如下所示