I have MainActivity with a fragment consisting of two tabs, with one fragment in each tab (ChatListFragment and FriendListFragment). Each fragment has ListView. When user tap on each row of ListView, ChatActivity will show.
I wanted ListView (with ListAdapter as adapter that calls ChatActivity) in ChatListFragment to update its ListView once ChatActivity closes. I have tried onActivityResult method as shown below in my code but requestCode is always -1.
MainActivity.java
public class MainActivity extends AppCompatActivity {
...
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: " + " " + requestCode + " == " + MYACTIVITY_REQUEST_CODE + " and " + resultCode + " == " + Activity.RESULT_OK);
Log.d(TAG, "onActivityResult: " + MainActivity.class.getSimpleName());
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
fragment.onActivityResult(requestCode, resultCode, data);
}
}
...
}
ChatListFragment.java
public class ChatListFragment extends Fragment {
...
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "onActivityResult: " + TAG);
Log.d(TAG, "onActivityResult: " + " " + requestCode + " == " + MYACTIVITY_REQUEST_CODE + " and " + resultCode + " == " + Activity.RESULT_OK);
if ((requestCode == MYACTIVITY_REQUEST_CODE) && (resultCode == Activity.RESULT_CANCELED)) {
List<Friend> friendList = getFriendChatList();
adapter = new ListAdapter(getActivity(), R.layout.fragment_list, friendList, true);
adapter.notifyDataSetChanged();
listView.setAdapter(adapter);
Log.d(TAG, "onActivityResult number of friend chats: " + getFriendChatList().size());
if(friendList.isEmpty()) {
linearLayout.setVisibility(View.VISIBLE);
} else {
linearLayout.setVisibility(View.GONE);
}
}
}
}
ChatActivity.java
public class ChatActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
if (getParent() == null) {
setResult(Activity.RESULT_OK);
} else {
getParent().setResult(Activity.RESULT_OK);
}
}
...
}
ListAdapter.java
public class ListAdapter extends ArrayAdapter<Friend> {
private static final int MYACTIVITY_REQUEST_CODE = 9000;
public ListAdapter(Context context, int resource, List<Friend> objects, boolean isChat) {
super(context, resource, objects);
this.context = context;
}
#Override
public View getView(final int position, final View convertView, ViewGroup parent) {
View view = convertView;
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(null == view) {
view = layoutInflater.inflate(R.layout.list_friend, null);
}
final Friend friend = friendList.get(position);
if(null != friend) {
final CardView rowLayout = (CardView) view.findViewById(R.id.row_layout);
final ImageView friendImage = (ImageView) view.findViewById(R.id.list_friend_image);
final TextView friendName = (TextView) view.findViewById(R.id.list_friend_name);
final TextView friendDescription = (TextView) view.findViewById(R.id.list_friend_description);
final TextView friendLastChatTime = (TextView) view.findViewById(R.id.list_friend_lastChatTime);
// Open chat activity
rowLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, ChatActivity.class);
intent.putExtra(KEY_FRIEND_NAME, friend.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
((Activity) context).startActivityForResult(intent, MYACTIVITY_REQUEST_CODE);
}
});
}
return view;
}
}
You need to make an Intent and then set the Result to that Intent.
Try something like this in your ChatActivity
Intent intent=new Intent();
if (getParent() == null) {
setResult(Activity.RESULT_OK,intent);
} else {
getParent().setResult(Activity.RESULT_OK,intent);
}
finish();
You also need to finish your ChatActivity after setting the result. Like this:
What I don't understand, is why you need to check for parent class. You can always simply do like this
Intent intent= new Intent();
setResult(RESULT_OK,intent);
finish();
And this should work properly.
Hope this helps :)
I know this is really late! But, the onActivityResult will not get the result which you set in setResult()!
Because you set Intent.FLAG_ACTIVITY_NEW_TASK in rowLayout.setOnClickListener
Based on reference
This flag can not be used when the caller is requesting a result from
the activity being launched.
SO, first of all, remove intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Then setResult(RESULT_OK,intent); in appropriate place
In this situation, you will get the response which you set, in onActivityResult
Related
I want to pick multiple or single images from phone gallery. But my code returning null pointer also one major problem I have notice the createChooser runs twice.
After tries two pick image two time it sends me to the parent activity
OnCreate Method
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_item_business);
ItemName = findViewById(R.id.item_name);
ItemDes = findViewById(R.id.item_des);
pickImage = findViewById(R.id.pickImage);
ChooseImageList = new ArrayList<>();
UrlsList = new ArrayList<>();
pickImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CheckPermission();
PickImageFromGallery();
}
});
}
Checking Permission
private void CheckPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(addItemBusiness.this,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(addItemBusiness.this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 2);
} else {
PickImageFromGallery();
}
}
}
Move to gallery
private void PickImageFromGallery() {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
startActivityForResult(Intent.createChooser(intent, "Select images"), 100);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
Log.i("result", "inside activity result");
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK) {
Log.i("result", "result is ok");
if (data.getClipData() != null) {
Log.i("result", "fine");
int count = data.getClipData().getItemCount();
for (int i = 0; i < count; i++) {
ImageUri = data.getClipData().getItemAt(i).getUri();
ChooseImageList.add(ImageUri);
SetAdapter();
}
} else if (data.getData() != null) {
Log.i("result", "clip data is null");
ImageUri = data.getData();
ChooseImageList.add(ImageUri);
SetAdapter();
}
}
}
Adapter
private void SetAdapter(){
ViewPagerAdapter adapter = new ViewPagerAdapter(this, ChooseImageList);
viewPager.setAdapter(adapter);
}
Adapter Class
private Context context;
ArrayList<Uri> ImageUrls;
LayoutInflater layoutInflater;
public ViewPagerAdapter(Context context, ArrayList<Uri> imageUrls) {
this.context = context;
ImageUrls = imageUrls;
layoutInflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return ImageUrls.size();
}
#NonNull
#Override
public Object instantiateItem(#NonNull ViewGroup container, int position) {
View view=layoutInflater.inflate(R.layout.show_imgaes_layout,container,false);
ImageView imageView=view.findViewById(R.id.UploadImage);
imageView.setImageURI(ImageUrls.get(position));
container.addView(view);
return view ;
}
#Override
public boolean isViewFromObject(#NonNull View view, #NonNull Object object) {
return view== object;
}
#Override
public void destroyItem(#NonNull View container, int position, #NonNull Object object) {
((RelativeLayout)object).removeView(container);
}
Hope that you can find the issue. Thank you
I have a fragment and I filled a RecyclerView in it, a post contains a camera and I need to take the information it brings when I take the photo. I do not know how to do it.
Please help.
This is mi code:
PostAdapter.java
public HeaderViewHolder (View itemView) {
super (itemView);
this.mCamera = (ImageView) itemView.findViewById(R.id.ivCamera);
mCameraPhoto = new CameraPhoto(itemView.getContext());
this.mCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try{
((Activity) v.getContext()).startActivityForResult(mCameraPhoto.takePhotoIntent(), CAMERA_REQUEST_ASIST);
}catch (Exception e){
Log.e("Error camera permission", e.getMessage());
}
}
});
}
MainActivity.java
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
String photoPath = mCameraPhoto.getPhotoPath();
for (Fragment fragment : getSupportFragmentManager().getFragments()) {
fragment.onActivityResult(requestCode, resultCode, data);
Log.d("Result in fragment",":D --> "+photoPath);
}
}
MyFragment.java
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d("Result in fragment",":D");
}
Pass fragment into PostAdapter's constructor.
class PostAdapter {
private Fragment fragment;
public PostAdapter(Fragment fragment) {
this.fragment = fragment;
}
}
then inside onclick
this.mCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try{
fragment.startActivityForResult(mCameraPhoto.takePhotoIntent(), CAMERA_REQUEST_ASIST);
}catch (Exception e){
Log.e("Error camera permission", e.getMessage());
}
}
});
Use one of getFragmentById() or getFragmentByTag() methods to get the reference to your fragment
You can get the information of the photo you took as the following.
In your fragment
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK){
if(requestCode == CAMERA_REQUEST_ASIST ){
String photoPath = mCameraPhoto.getPhotoPath();
try {
// Update data in your Custom RecyclerView Adapter
// and call notifyDatasetChanged
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}//end if resultCode
}
And more information https://github.com/kosalgeek/PhotoUtil/blob/master/README.md
I created below class but numbers is coming null. The same code is working fine with activity. I have made changes in context of Fragment. What else is creating problem in the code.
public class TestFrag extends Fragment {
private static final String[] phoneProjection = new String[]{ContactsContract.CommonDataKinds.Phone.DATA};
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.testfrag, container, false);
TextView textView = (TextView) view.findViewById(R.id.clickme);
EditText editText = (EditText) view.findViewById(R.id.contact);
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
getActivity().startActivityForResult(intent, 1);
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case (1):
//ContentResolver cr = getContentResolver();
Uri contactData = data.getData();
Cursor c = getActivity().getContentResolver().query(contactData, phoneProjection, null, null, null);
if (c.moveToFirst()) {
String numbers = c.getString(0);
Log.e("Hi", numbers);
}
break;
}
}
}
you are calling getActivity().startActivityForResult(intent, 1); it's response will be handled in activity's onActivityResult() method you should call startActivityForResult(intent, 1); which is fragment's method and will call the fragments onActivityResult().
you can check this link too
im currently doing a app that has a barcode scanner. currently when i scanned the barcode it is suppose to display the format of the barcode and the contents also. but currently it doesnt display the format and contents after scanning.
here is the code
public class ThreeFragment extends Fragment{
public ThreeFragment() {
// Required empty public constructor
}
Button scan_btn;
EditText Edit_current;
TextView formatTxt, contentTxt;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
scan_btn = (Button) view.findViewById(R.id.scan_button);
final Activity activity = getActivity();
scan_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result.getContents() != null) {
if (result.getContents() != null){
String scanContent = result.getContents();
String scanFormat = result.getFormatName();
// display it on screen
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
} else {
Toast toast = Toast.makeText(getContext(),"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
}
my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button android:id="#+id/scan_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/scan" />
<TextView
android:id="#+id/scanFormat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_below="#id/scan_button" />
<TextView
android:id="#+id/scanContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_centerHorizontal="true"
android:layout_below="#id/scanFormat" />
</RelativeLayout>
i have edit the code to this
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
scan_btn = (Button) view.findViewById(R.id.scan_button);
formatTxt = (TextView) view.findViewById(R.id.scanFormat);
contentTxt = (TextView) view.findViewById(R.id.scanContent);
final Activity activity = getActivity();
scan_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result.getContents() != null) {
if (result.getContents() == null){
Toast toast = Toast.makeText(getContext(),"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}else{
String scanContent = result.getContents();
String scanFormat = result.getFormatName();
// display it on screen
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}
}
}}
still cant display the format and contents
Initialize your formatTxt & contentTxt in your onCreateView() method!
Scan is alright, it just gives NPE because of not initializing TextView
scan_btn = (Button) view.findViewById(R.id.scan_button);
formatTxt = (TextView) view.findViewById(R.id.scanFormat);
contentTxt = (TextView) view.findViewById(R.id.scanContent);
and in your activityResult
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result.getContents() != null) {
String scanContent = result.getContents();
String scanFormat = result.getFormatName();
// display it on screen
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}
}
update: that's how it look in your code.
public class ThreeFragment extends Fragment{
public ThreeFragment() {
// Required empty public constructor
}
Button scan_btn;
EditText Edit_current;
TextView formatTxt, contentTxt;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_one, container, false);
scan_btn = (Button) view.findViewById(R.id.scan_button);
//initialize the textViews
formatTxt = (TextView) view.findViewById(R.id.scanFormat);
contentTxt = (TextView) view.findViewById(R.id.scanContent);
final Activity activity = getActivity();
scan_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
IntentIntegrator integrator = new IntentIntegrator(activity);
integrator.setDesiredBarcodeFormats(IntentIntegrator.PRODUCT_CODE_TYPES);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(false);
integrator.setBarcodeImageEnabled(true);
integrator.initiateScan();
}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result.getContents() != null) {
String scanContent = result.getContents();
String scanFormat = result.getFormatName();
// display it on screen
formatTxt.setText("FORMAT: " + scanFormat);
contentTxt.setText("CONTENT: " + scanContent);
}else {
Toast toast = Toast.makeText(getContext(),"No scan data received!", Toast.LENGTH_SHORT);
toast.show();
}
}
}
package com.sp.ez_mart_xy;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new OneFragment(), "NAVIGATION");
adapter.addFragment(new TwoFragment(), "HOME");
adapter.addFragment(new ThreeFragment(), "PRICE-CHECKER");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}
this is my mainactivty but i dont see any errors
There are at least two issues with your code:
You have the same if statement twice:
if (result.getContents() != null) {
if (result.getContents() != null){
The outer one does not have an else, so you will not know when the condition fails even though the inner one does have an else.
formatTxt is not initialized. You need to add a call to findViewById() somewhere in onCreateView() to initialize it.
I am trying to create a group of phone contacts in CreateGroup.java . So, for that purpose, I go to a new activity named ContactsView.java using an Intent. There I a get list of all contacts. When I click a contact from that list, it gets the name of that contact item and returns it back to the previous activity named CreateGroup.java. But when I try to add more contacts, it is replacing the previous added item in the listview. I am unable to add more than one contact in my list.
Please someone help me!!
CreateGroup.java
public class CreateGroup extends ActionBarActivity {
TextView textView;
ListView show;
ArrayList<String> addArray=new ArrayList<String >();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_group);
ImageButton next = (ImageButton)findViewById(R.id.imgButtonAddContacts);
textView=(TextView)findViewById(R.id.textViewtst);
show= (ListView) findViewById(R.id.listView2);
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = new Intent(view.getContext(), ContactsView.class);
startActivityForResult(myIntent, 0);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (0) : {
if (resultCode == Activity.RESULT_OK) {
String newText = data.getStringExtra("CName");
addArray.add(newText);
ArrayAdapter<String>adapter=new ArrayAdapter<String> (CreateGroup.this,android.R.layout.simple_list_item_1,addArray);
show.setAdapter(adapter);
}
break;
}
}
}
}
here is ContactsView.java
public class ContactsView extends ActionBarActivity {
String namecsv="";
String phonecsv="";
String namearray[];
String phonearray[];
ListView lv1;
ArrayList<String> list_items= new ArrayList<String>();
//declare a variable for counting of selected items.
int count=0;
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contacts_view);
lv1=(ListView)findViewById(R.id.listView);
list_items.add("one");
Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
while (phones.moveToNext()){
String name= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phonenumber= phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if(name!=null){
namecsv+=name + ",";
phonecsv+=phonenumber + ",";
}
}
phones.close();
namearray= namecsv.split(",");
phonearray=phonecsv.split(",");
final ArrayAdapter <String> adapter = new ArrayAdapter <String> (this,android.R.layout.simple_list_item_1,android.R.id.text1,namearray);
lv1.setAdapter(adapter);
lv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String msgname = namearray[position];
String msgnum = phonearray[position];
Toast.makeText(getApplicationContext(), msgname + " " + msgnum, Toast.LENGTH_SHORT).show();
Intent resultIntent = new Intent();
resultIntent.putExtra("CName", msgname);
setResult(Activity.RESULT_OK, resultIntent);
finish();
}
});
}
}
I have updated my code according to the answer provided. but still facing the same problem. its only show only on last add item in the listview. previous item removes.
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case (0) : {
if (resultCode == Activity.RESULT_OK) {
String newText = data.getStringExtra("CName");
textView.setText(newText);
addArray.add(newText);
adapter.notifyDataSetChanged();
show.setAdapter(adapter);
}
break;
}
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
You should not call super.onActivityResult(requestCode, resultCode, data); as very first thing, there but only when you face requestCode that is not handled by your code. In other words, this should be added to switch block, in default section. Other thing is that you should not set new adapter each time. So this:
addArray.add(newText);
ArrayAdapter<String>adapter=new ArrayAdapter<String> (CreateGroup.this,android.R.layout.simple_list_item_1,addArray);
show.setAdapter(adapter);
should be replaced by:
addArray.add(newText);
adapter.notifyDatasetChanged();
which simply adds data to your current array then notify the adapter (which you need to create in onCreate() additionally of course) about the change in dataset.