0

I have created a TabbedActivity as the main screen for my APP, also i have created a fragment (used inside the TabbedActivity )to display whenever a particular tab is clicked. Inside one of the fragment i am using AutoComplteTextView Problem is that the AutoComplteTextView do not display any suggestions mentioned in the String array list also i am not getting any errors in the log could any direct to solve this problem Code TabbedActivity from where the fragment is called

  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            if (getArguments().getInt(ARG_SECTION_NUMBER) == 1){
                View viewMakeTransaction = inflater.inflate(R.layout.fragment_make_transaction, container, false);
                return viewMakeTransaction;
            }
            else if(getArguments().getInt(ARG_SECTION_NUMBER) == 2){
                View viewAddCustomer = inflater.inflate(R.layout.fragment_add_customer, container, false);
                return viewAddCustomer;
            }
            else if (getArguments().getInt(ARG_SECTION_NUMBER) == 3){
                View viewViewTransaction = inflater.inflate(R.layout.fragment_view_transaction, container, false);
                return viewViewTransaction;
            }
            else{

                View rootView = inflater.inflate(R.layout.fragment_main, container, false);
                TextView textView = (TextView) rootView.findViewById(R.id.section_label);
                textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
                return rootView;
            }
        }

Fragment (fragment_make_transaction) Code having the AutocompletTextView

private static final String[] COUNTRIES = new String[]{"India","America"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View viewMakeTransactionFragment = inflater.inflate(R.layout.fragment_make_transaction, container, false);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,COUNTRIES);
    final AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewMakeTransactionFragment.findViewById(R.id.selectCustomer);
    autoCompleteTextView.setAdapter(adapter);
    return viewMakeTransactionFragment;
}

Steps to recreate the problem 1. Create a new Android Project - Select TabbedActivity and Navigation Style as -ActionBarTabs(with page viewer) as show in the below pictureTabbedActivity

  1. Click finish - Project will be created
  2. Create a new blank Fragment
  3. Edit the code from the fragment as below fragment code as of now

    package demo.com.problem;

    import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup;

    public class BlankFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_blank, container, false); } }

  4. go to TabbedActivity - java code inside the method (onCreateView) call the fragment using the below code

this will call the fragment when the user is on the first screen of the tabbed activity

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    if (getArguments().getInt(ARG_SECTION_NUMBER) == 1){
        View viewMakeTransaction = inflater.inflate(R.layout.fragment_blank, container, false);
        return viewMakeTransaction;
    }
    else{

        View rootView = inflater.inflate(R.layout.fragment_main, container, false);
        TextView textView = (TextView) rootView.findViewById(R.id.section_label);
        textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
        return rootView;
    }
}

Run the app once to make sure the fragment is getting displayed under section 1

Steps to Add AutoCompleteTextView to the fragment

  1. XML file for the fragment

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_blank_fragment" />
    
    <AutoCompleteTextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    

  2. Java code for the fragment

    package demo.com.problem;

    import android.content.Context; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v7.widget.AppCompatAutoCompleteTextView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView;

    public class BlankFragment extends Fragment { AutoCompleteTextView autoCompleteTextView; private static final String[] COUNTRIES = new String[]{"India","Aus"};

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
    
        View view = inflater.inflate(R.layout.fragment_blank, container, false);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,COUNTRIES);
        autoCompleteTextView = (AutoCompleteTextView) view.findViewById(R.id.textView);
        autoCompleteTextView.setAdapter(adapter);
        // Inflate the layout for this fragment
        return view;
    }
    

    }

Issues with the AutoComplete text view enter image description here

Brijesh
  • 25
  • 3
  • 9

0 Answers0