我在android中做了一个简单ListDEmo
的......有两个activity.in第一个activity 3个edittexts和2个按钮插入和取消......在第二个活动中,有一个ListView
和一个按钮“返回”,
现在我想要是"Insert"
按下按钮时..三个的值EditTexts
应该显示在ListView
其他活动上..我的代码如下:
MainActivity.java
package com.example.listdemo;
import java.util.ArrayList;
import android.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button b1,b2;
EditText e1,e2,e3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText e1=(EditText)findViewById(R.id.editText1);
final EditText e2=(EditText)findViewById(R.id.editText2);
final EditText e3=(EditText)findViewById(R.id.editText3);
// final ArrayList<String> noteList = new ArrayList<String>();
//final ArrayAdapter<String> aa;
b1=(Button)findViewById(R.id.button1);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String s1 = e1.getText().toString();
String s2 = e1.getText().toString();
String s3 = e1.getText().toString();
//Intent i =new Intent(MainActivity.this,SecondActivity.class);
Intent i = new Intent(MainActivity.this,SecondActivity.class);
i.putExtra("edit1", s1);
i.putExtra("edit2", s2);
i.putExtra("edit3", s3);
startActivity(i);
startActivity(i);
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
}
});
}
}
SecondActivity.java
package com.example.listdemo;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.sax.StartElementListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class SecondActivity extends ListActivity {
ListView lv;
Button bt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
lv=(ListView)findViewById(R.id.listView1);
String[] list = new String[3];
list[0] = getIntent().getStringExtra("edit1");
list[1] = getIntent().getStringExtra("edit2");
list[2] = getIntent().getStringExtra("edit3");
lv.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1,list));
// Toast.makeText(getApplicationContext(), st1, Toast.LENGTH_LONG).show();
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i =new Intent(SecondActivity.this,MainActivity.class);
startActivity(i);
}
});
}
}
请帮帮我..!谢谢你们