Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. ListView list = (ListView) findViewById(R.id.listView);
  2. list.setAdapter(new MyAdapter(this, names));
  3. list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  4. @Override
  5. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  6. Names name = names.get(position);
  7. if (position == 7) {
  8.  
  9. Intent mintent = new Intent(MainActivity.this,EditActivity.class);
  10. startActivityForResult(mintent, CHOOSEPH_REQ);
  11.  
  12. }
  13. }
  14.  
  15. }
  16.  
  17. });
  18.  
  19. }
  20.  
  21. @Override
  22. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  23. super.onActivityResult(requestCode, resultCode, data);
  24. if (requestCode==CHOOSEPH_REQ){
  25. if (resultCode==RESULT_OK){
  26. String name = data.getStringExtra("name");
  27.  
  28.  
  29. }
  30. }
  31. }
  32.  
  33. public class MyAdapter extends ArrayAdapter<Names> {
  34.  
  35. public MyAdapter(Context context, List<Names> objects) {
  36. super(context, R.layout.list_item, objects);
  37.  
  38. }
  39.  
  40. @Override
  41. public View getView(int position, View convertView, ViewGroup parent) {
  42. View rowView = getLayoutInflater().inflate(R.layout.list_item, parent, false);
  43. TextView name = (TextView) rowView.findViewById(R.id.name);
  44. TextView email = (TextView) rowView.findViewById(R.id.email);
  45. TextView phone = (TextView) rowView.findViewById(R.id.phone);
  46. TextView street = (TextView) rowView.findViewById(R.id.street);
  47. ImageView imageView = (ImageView) rowView.findViewById(R.id.image);
  48. name.setText(getItem(position).name);
  49. email.setText(getItem(position).eMail);
  50. phone.setText(getItem(position).phone);
  51. street.setText(getItem(position).street);
  52. imageView.setImageResource(prgmImages[position]);
  53.  
  54.  
  55. return rowView;
  56.  
  57. }
  58. }
  59.  
  60. public static class Names implements Parcelable{
  61. String name;
  62. String eMail;
  63. String phone;
  64. String street;
  65.  
  66. public Names(String name, String eMail, String phone, String street) {
  67. this.name = name;
  68. this.eMail = eMail;
  69. this.phone = phone;
  70. this.street = street;
  71. }
  72.  
  73.  
  74. protected Names(Parcel in) {
  75. name = in.readString();
  76. eMail = in.readString();
  77. phone = in.readString();
  78. street = in.readString();
  79. }
  80.  
  81. public static final Creator<Names> CREATOR = new Creator<Names>() {
  82. @Override
  83. public Names createFromParcel(Parcel in) {
  84. return new Names(in);
  85. }
  86.  
  87. @Override
  88. public Names[] newArray(int size) {
  89. return new Names[size];
  90. }
  91. };
  92.  
  93. @Override
  94. public int describeContents() {
  95. return 0;
  96. }
  97.  
  98. @Override
  99. public void writeToParcel(Parcel dest, int flags) {
  100. dest.writeStringArray(new String[] { name, eMail, phone, street });
  101. }
  102. }
  103.  
  104. Intent data = new Intent();
  105. data.putExtra("name",c);
  106. setResult(RESULT_OK,data);
  107. finish();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement