[英]How change Textcolor for only one String in for loop?
A basically question-> because i cant find a answer since a lot of days... if i have a for loop
(10 times) and each output is a different string
. 一个基本的问题->因为我已经很多天都找不到答案了...如果我有一个
for loop
(10次)并且每个输出都是不同的string
。 How can i make a specific String-output
colored? 如何使特定的
String-output
彩色?
for(int i=0; i< posts.length();i++ ) {
JSONObject post = posts.optJSONObject(i);
this.title = post.optString("title");
blogTitles[i] = title;
}
Sure i can sort the specific blogtitles[i]
by code 确保我可以按代码对特定
blogtitles[i]
进行排序
title.toLowerCase().contains("neune")
but if i try to give it the new layout
, he layout
is used for all (10x) outputs any can help? 但如果我尝试给它新的
layout
,他layout
用于所有(10倍)输出任何能帮忙吗?
Thx for answer now i changed to 谢谢答案,现在我改为
JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
but still all outputs are black and in layout "android.R.layout.simple_list_item_1" 但仍然所有输出均为黑色,并且布局为“ android.R.layout.simple_list_item_1”
complete code 完整的代码
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, android.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];
}
}
only the second layout is used.... i guess it is because "title.toLowerCase().contains("neune") && title.contains(this.id.toLowerCase())" is true and "title.toLowerCase().contains("neune")" is true.... it "must" be this way, because each (i)output should be evaluated 仅使用第二种布局。...我猜是因为“ title.toLowerCase()。contains(“ neune”)&& title.contains(this.id.toLowerCase())“是真实的,并且” title.toLowerCase( ).contains(“ neune”)“是正确的。...“必须”采用这种方式,因为每个(i)输出都应进行评估
Parse Json
as follows. 解析
Json
如下。
JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
Edit: 编辑:
String getStr; 字符串getStr;
for(int i=0; i< posts.length();i++ ) {
JSONObject post = posts.optJSONObject(i);
this.title = post.optString("title");
blogTitles[i] = title;
getStr = blogTitles[i];
if("neune".equals(getStr)){
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString redSpannable= new SpannableString(getStr);
redSpannable.setSpan(new ForegroundColorSpan(Color.RED), 0, getStr, 0);
builder.append(redSpannable);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.