1

I have a listview that has values loaded in from my sqlite database which I was getting help with from this question that I posted, Loading two SQL columns into a listview but only need to display the first column Android

When the user clicks on the item, it shows the name and phone number selected with the toast display, but on the Commands fragment, where I want to show which name has been selected, it is always defaulting to showing that listview is empty, even when I've clicked on an item in the listview to be selected for communication. I want to display the name selected on that textview which is not working.

SelectModemFragment.java

public static String SelectedName = null;
public static String SelectedPhNo = null;

display_contacts1.setOnItemClickListener(new AdapterView.OnItemClickListener()
            {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id)
                {
                    //String namedisplay = arrayAdapter.getItem(position); //<<<<<<<<<< this gets the phone name
                    String namedisplay = myCursor.getString(myCursor.getColumnIndex(DataDBAdapter.COl_MYTABLE_PHONENAME));
                    String phoneno_display = myCursor.getString(myCursor.getColumnIndex(DataDBAdapter.COL_MYTABLE_PHONENUMBER));

                    Toast.makeText(view.getContext(), namedisplay + " Selected for Communication", Toast.LENGTH_SHORT).show();
                    Toast.makeText(view.getContext(), phoneno_display, Toast.LENGTH_SHORT).show();

                    // Set the selected contact variables
                    SelectedName = namedisplay;
                    SelectedPhNo = phoneno_display;
                }
             });

CommandsFragment.java

     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            View view = inflater.inflate(R.layout.fragment_commands_view, container, false);

            if(SelectModemFragment.display_contacts.isEmpty() )
            {
                SelectedPhNo = null;

                // No contacts selected from the Add Modem listview
                modemView.setText("No contact selected");
            }
            else
            {
                modemView.setText(SelectedName);
            }

            return view;
        }
Sahil Bora
  • 173
  • 1
  • 12

0 Answers0