broadcastreceiver接受数据 动态创建控件

package my.aborder2;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class OneProductSet extends Activity {
 OneProductSetReceiver onereceiver;
 private List<proxxx> lis;//存储的EditText值
 
  TextView tv;
  LinearLayout liner;
  Button btn;
 String sss="";
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.oneproductset);
  
  
  onereceiver = new OneProductSetReceiver();
  // 创建IntentFilter
  IntentFilter filter = new IntentFilter();
  // 指定BroadcastReceiver监听的Action
  filter.addAction("UPDATE_ACTION");
  // 注册BroadcastReceiver
  registerReceiver(onereceiver, filter);
  tv = (TextView) findViewById(R.id.oneprodutsettextView1);
  liner = (LinearLayout) findViewById(R.id.oneproductsetliner);
  lis =new ArrayList<proxxx>() ;
  btn = (Button) findViewById(R.id.oneproductsetbutton1);
  btn.setOnClickListener(new OnClickListener() {
   
   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    for(proxxx x:lis)
    {
     sss = sss+" " + x.getEt().getText().toString();
     
    }
    tv.setText(sss);
   }
  });
 }
 
 
 
 public class OneProductSetReceiver extends BroadcastReceiver
 {

  @Override
  public void onReceive(Context context, Intent intent) {
   // TODO Auto-generated method stub
   
   Bundle bundle = intent.getExtras();
  try {
   JSONObject projson= new JSONObject( bundle.getString("projson"));
   tv.setText(projson.toString());
   
   //EditText et = new EditText(OneProductSet.this);
   //et.setTextSize(20);
   //et.setText(projson.toString());
   //liner.addView(et);
//   Toast.makeText(context , "接收到的Intent的Action为:"
//     + projson.optString("proid")
//     , 5000)
//     .show(); 
   proxxx px = new proxxx();
   px.setProid(projson.optString("proid"));
   TextView tvt = new TextView(OneProductSet.this);
   tvt.setTextSize(20);
   tvt.setText(px.getProid());
   tvt.setLayoutParams(new LinearLayout.LayoutParams(      
     100,      
                 40 //LinearLayout.LayoutParams.WRAP_CONTENT      
         ));
   EditText et = new EditText(OneProductSet.this);
   et.setTextSize(20);
   et.setLayoutParams(new LinearLayout.LayoutParams(      
     100,      
                 40 //LinearLayout.LayoutParams.WRAP_CONTENT      
         ));
   px.setEt(et);
   
   LinearLayout container = new LinearLayout(context);
   container.setOrientation(LinearLayout.HORIZONTAL);
   container.setLayoutParams(new ListView.LayoutParams(      
     ListView.LayoutParams.FILL_PARENT,      
     ListView.LayoutParams.WRAP_CONTENT     
         ) );
   container.addView(tvt);
   container.addView(et);
   
   liner.addView(container);
   lis.add(px);
   
  } catch (JSONException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
   
   
   
  }
  
  
  
  
 }

}

你可能感兴趣的:(broadcastreceiver接受数据 动态创建控件)