0
我想根据json数组长度添加RelativeLayout XML文件。使用LayoutInflater添加RelativeLayout并将Text设置为TextView
for (int i = 0; i < jsonArray.length(); i++) {
Log.i("Length", "Is " + jsonArray.length());
JSONObject customer = jsonArray.getJSONObject(i);
Log.e("Customer", "is " + jsonArray.getJSONObject(i));
RelativeLayout rl[] = new RelativeLayout[jsonArray.length()];
rl[i] = new RelativeLayout(ChatActivity.this);
if (sharedPrefsUser.getInt(SharedPrefsInformation.ID_FROM_LOGGED_IN_USER, -1) != sender) {
rl[i] = (RelativeLayout) getLayoutInflater().inflate(R.layout.message_left, null);
} else {
rl[i] = (RelativeLayout) getLayoutInflater().inflate(R.layout.message_right, null);
}
TextView textViewMessage = (TextView) rl[i].findViewById(R.id.txtMessage);
textViewMessage.setText(customer.getString("message"));sharedPrefsUser.getInt(SharedPrefsInformation.ID_FROM_LOGGED_IN_USER, -1));
// Log.i("")
Log.e("Message", "is " + customer.getString("message"));
linearLayoutWithMessages.addView(rl[i]);
}
但现在将只添加一次...... JSON的arary长度为4个。有什么建议么?谢谢..
遗憾的是没有:-( – FabASP
这是不是给预期的结果或外面的for循环呢?现在你创建一个新的数组每次和一个项目添加到它无法创建RelativeLayout的数组。 – Bram
它没有给我预期的结果.. – FabASP