Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ListView list = (ListView) findViewById(R.id.listView);
- list.setAdapter(new MyAdapter(this, names));
- list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Names name = names.get(position);
- if (position == 7) {
- Intent mintent = new Intent(MainActivity.this,EditActivity.class);
- startActivityForResult(mintent, CHOOSEPH_REQ);
- }
- }
- }
- });
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode==CHOOSEPH_REQ){
- if (resultCode==RESULT_OK){
- String name = data.getStringExtra("name");
- }
- }
- }
- public class MyAdapter extends ArrayAdapter<Names> {
- public MyAdapter(Context context, List<Names> objects) {
- super(context, R.layout.list_item, objects);
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View rowView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
- TextView name = (TextView) rowView.findViewById(R.id.name);
- TextView email = (TextView) rowView.findViewById(R.id.email);
- TextView phone = (TextView) rowView.findViewById(R.id.phone);
- TextView street = (TextView) rowView.findViewById(R.id.street);
- ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
- name.setText(getItem(position).name);
- email.setText(getItem(position).eMail);
- phone.setText(getItem(position).phone);
- street.setText(getItem(position).street);
- imageView.setImageResource(prgmImages[position]);
- return rowView;
- }
- }
- public static class Names implements Parcelable{
- String name;
- String eMail;
- String phone;
- String street;
- public Names(String name, String eMail, String phone, String street) {
- this.name = name;
- this.eMail = eMail;
- this.phone = phone;
- this.street = street;
- }
- protected Names(Parcel in) {
- name = in.readString();
- eMail = in.readString();
- phone = in.readString();
- street = in.readString();
- }
- public static final Creator<Names> CREATOR = new Creator<Names>() {
- @Override
- public Names createFromParcel(Parcel in) {
- return new Names(in);
- }
- @Override
- public Names[] newArray(int size) {
- return new Names[size];
- }
- };
- @Override
- public int describeContents() {
- return 0;
- }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeStringArray(new String[] { name, eMail, phone, street });
- }
- }
- Intent data = new Intent();
- data.putExtra("name",c);
- setResult(RESULT_OK,data);
- finish();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement