【发布时间】:2015-08-22 04:08:25
【问题描述】:
我想根据 json 数组长度添加一个 RelativeLayout XML 文件。
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 数组长度为四。有什么建议么?谢谢..
【问题讨论】:
标签: android json android-layout