实现 动态追加Imageview 追加ChildView



package xxxx;

import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import x.R;
import x.BitmapManage;
import x.StringUtil;
import x.C_BaseActivity;

public class C_My1Demand_Detail extends C_BaseActivity {
	
	private TextView title,author,time,demandDesc,replyAccount;
	private ImageView imgs[],shopIcon;
	private ViewGroup viewGroup;
	private Context context = this;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.correcting_my_demand_detail);
		
		initViews();
		loadData();
	}
	
	private void initViews() {
		
		title = (TextView) findViewById(R.id.title);
		author = (TextView) findViewById(R.id.author);
		time = (TextView) findViewById(R.id.time);
		demandDesc = (TextView) findViewById(R.id.demand_desc);
		replyAccount = (TextView) findViewById(R.id.reply_account);
		/*shopName = (TextView) findViewById(R.id.shop_name);
		replyWord = (TextView) findViewById(R.id.reply_word);
		replyTime = (TextView) findViewById(R.id.reply_time);*/
		imgs = new ImageView[3];
		imgs[0] = (ImageView) findViewById(R.id.img1);
		imgs[1] = (ImageView) findViewById(R.id.img2);
		imgs[2] = (ImageView) findViewById(R.id.img3);
		viewGroup = (ViewGroup) findViewById(R.id.view_group);
	}
	
	private void loadData() {
		
		String perData = getIntent().getExtras().get("per_data").toString();
		
		if (!StringUtil.isEmpty(perData)) {
			try {
				
				String fdDemaTitle = new JSONObject(perData).getString("fdDemaTitle");
				String fdBuyeName = "";
				try {
					fdBuyeName = new JSONObject(new JSONObject(perData).getString("propBuyer")).getString("fdBuyeName");
				} catch (Exception e) {
				}
				
				String fdDemaCreateAt = new JSONObject(perData).getString("fdDemaCreateAt");
				String fdDemaRemark = new JSONObject(perData).getString("fdDemaRemark");
				JSONArray propImages = new JSONArray(new JSONObject(perData).getString("propImages"));
				String [] fdDeimImages = new String[propImages.length()];
				
				for (int i = 0 ;i < propImages.length(); i++ ) {
					
					fdDeimImages [i] = new JSONObject(propImages.get(i).toString()).getString("fdDeimImage");
					
				}
				
				String propReplyCount = new JSONObject(perData).getString("propReplyCount");
				JSONArray propReplys = new JSONArray(new JSONObject(perData).getString("propReplys"));
				String fdDereContent[] = new String[propReplys.length()];
				String fdDereCreateAt[] = new String[propReplys.length()];
				String fdShopName[] = new String[propReplys.length()];
				String fdShopLogo[] = new String[propReplys.length()];
				
				for (int i = 0 ;i < propReplys.length(); i++ ) {
					
					fdDereContent[i] = new JSONObject(propReplys.get(i).toString()).getString("fdDereContent");
					fdDereCreateAt[i] = new JSONObject(propReplys.get(i).toString()).getString("fdDereCreateAt");
					fdShopLogo[i] = new JSONObject(new JSONObject(propReplys.get(i).toString()).getString("propShop")).getString("fdShopLogo");
					fdShopName[i] = new JSONObject(new JSONObject(propReplys.get(i).toString()).getString("propShop")).getString("fdShopName");
					
				}
			
				title.setText(fdDemaTitle);
				author.setText(fdBuyeName);
				time.setText(fdDemaCreateAt);
				demandDesc.setText(fdDemaRemark);
				replyAccount.setText(propReplyCount);
				
				for (int i = 0 ;i < propReplys.length(); i++ ) { 
					
					TextView shopName,replyWord,replyTime;
					ImageView shopIcon;
					LayoutInflater inflater = LayoutInflater.from(context);
					RelativeLayout reply = (RelativeLayout) inflater.inflate(R.layout.correcting_my_demand_detail_reply, null);
					shopName = (TextView) reply.findViewById(R.id.shop_name);
					replyWord = (TextView) reply.findViewById(R.id.reply_word);
					replyTime = (TextView) reply.findViewById(R.id.reply_time);
					shopIcon = (ImageView) reply.findViewById(R.id.shop_icon);
					BitmapManage.getInstance(context).get(fdShopLogo[0], shopIcon);
					shopName.setText(fdShopName[i]);
					replyWord.setText(fdDereContent[i]);
					replyTime.setText(fdDereCreateAt[i]);
					viewGroup.addView(reply);
					if ( ! (propReplys.length() == 1 || propReplys.length()-1 == i)) {
						
						ImageView iv = new ImageView(context);
						iv.setBackgroundColor(0xaaaaaa);
						LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(viewGroup.getLayoutParams().width, 1);
						lp.setMargins(0, 10, 0, 0);
						iv.setBackgroundColor(Color.parseColor("#000000"));
						iv.setLayoutParams(lp);
						viewGroup.addView(iv);
						
					}
					viewGroup.setVisibility(View.VISIBLE);
					
				}
				for (int i=0 ; i < fdDeimImages.length ; i++) {
					
					BitmapManage.getInstance(context).get(fdDeimImages[i], imgs[i]);
					imgs[i].getLayoutParams();
					imgs[i].setVisibility(View.VISIBLE);
					
				}
				
			} catch (Exception e) {
				Toast.makeText(context, "数据加载异常!", Toast.LENGTH_SHORT).show();
				return;
			}
		}
	}
	
}





                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值