listview重写baseAdapter,两个activity,listview里item有一个textview和edittext显示activity2输入的数据

代码:publicclassMainActivityextendsActivity{privateListViewlistView;Myadapteradapter=ne... 代码:
public class MainActivity extends Activity {
private ListView listView;
Myadapter adapter=new Myadapter();
People people;//我自己写的一个people类,两个属性,姓名,QQ
ArrayList<People> list = new ArrayList<People>();
private Button bt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = (ListView) findViewById(R.id.listView1);
bt = (Button) findViewById(R.id.button1);
listView.setAdapter(adapter);
bt.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myintent = new Intent();
myintent.setClass(MainActivity.this, Activity2.class);
MainActivity.this.startActivityForResult(myintent,10);
}});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
people=(People)data.getSerializableExtra("list");
list.add(people);
adapter.notifyDataSetChanged();
}

class Myadapter extends BaseAdapter{
private LayoutInflater mInflater = null;

public int getCount() {
return list.size();
}

public Object getItem(int arg0) {
return arg0;
}

public long getItemId(int arg0) {
return arg0;
}
//adapter绑定数据
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null)
{
convertView = mInflater.inflate(R.layout.listview, null);
}
TextView tv = (TextView)convertView.findViewById(R.id.name_tv);
TextView ed = (TextView)convertView.findViewById(R.id.qq_ed);;
tv.setText(list.get(position).toString());
ed.setText(list.get(position).toString());
return convertView;

}
};

public class Activity2 extends Activity {
Button bt1;
EditText name,qq;
People people;
ArrayList<People> list=new ArrayList<People>();
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
bt1=(Button)findViewById(R.id.button1);
name=(EditText)findViewById(R.id.editText1);
qq=(EditText)findViewById(R.id.editText2);
qq.setInputType(EditorInfo.TYPE_CLASS_PHONE);
bt1.setOnClickListener(new MyClickListener());
}

class MyClickListener implements OnClickListener
{
public void onClick(View e)
{
people.setName(name.getText().toString());
people.setQq(qq.getText().toString());
list.add(people);
Intent intent=new Intent();
intent.putExtra("list",list);
setResult(0, intent);
finish();
}
展开
 我来答
guanyayang
2012-12-29
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
1.接口回调
2.handle发消息
3.broadcast广播
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
abey_bert
2012-11-29
知道答主
回答量:0
采纳率:0%
帮助的人:0
展开全部
传值
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
?>

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式