【发布时间】:2016-09-03 10:13:06
【问题描述】:
一个基本的问题-> 因为我很多天都找不到答案...
如果我有一个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)输出
有什么可以帮忙的吗?
感谢回答,现在我改为
JSONObject post = posts.getJSONObject(i);
this.title = post.getString("title");
但所有输出仍然是黑色的,并且布局为“android.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, 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];
}
}
只使用了第二个布局....我猜这是因为“title.toLowerCase().contains("neune") && title.contains(this.id.toLowerCase())” 是真的并且“title .toLowerCase().contains("neune")" 是真的......它“必须”是这样的,因为每个(i)输出都应该被评估
【问题讨论】:
-
使用
post.getJsonObject(i) -
你的意思是 post.getJsonObject(i).contains("neune")? (对不起,我是 android 的新手)
-
@Newbster optstring 与 getString() 相比是一个好方法。stackoverflow.com/a/13790789/3960700
标签: java android android-layout android-studio