• 13

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I have a Sqlite table like below.

enter image description here

I have made a list with the rawQuery : SELECT HEADER FROM MyData GROUP BY HEADER

 ArrayAdapter arrayAdapter;
 ArrayList<String> listItem = new ArrayList<>();
 final ListView listView = (ListView) view.findViewById(R.id.list);

 SQLiteDatabase sqLiteDatabase = 
 Cursor cursor = sqLiteDatabase.rawQuery("SELECT HEADER FROM MyData GROUP BY 
HEADER", new String[]{});

     if (cursor.getCount() == 0) {
         Toast.makeText(getActivity(), "No Data to show", 
     } else {
         while (cursor.moveToNext()) {
         arrayAdapter = new ArrayAdapter<>(getActivity(), 
android.R.layout.simple_list_item_1, listItem);

List shows as below:

Letter Number Word

My problem is when I click on list item Suppose(Letter), SwipeViews shows A,

when click on Number SwipeViews shows B and

when click on Word SwipeViews shows C

I want to get, when I will click on Letter, SwipeViews will show only A,B,C

when I will click on Number, SwipeViews will show only 1,2,3

when I will click on Word, SwipeViews will show only Apple, Orange and Banana

This is OnClickListener

listView.setOnItemClickListener(new OnItemClickListener() {
     public void onItemClick(AdapterView<?> adapterView, View view, int i, 
   long l) {
         Intent intent=new Intent(getActivity(), SwipeNav.class);
         intent.putExtra(ID_EXTRA, String.valueOf(l));

This is from Pager Adapter

public class MyPagerAdapter extends FragmentStatePagerAdapter {
private Context context;
public MyPagerAdapter(FragmentManager fm, Context context) {
    this.context= context;}
public Fragment getItem(int i) {
    ArrayList<String> listItem = new ArrayList<String>();
    SQLiteDatabase sqLiteDatabase = 
    Cursor cursor = sqLiteDatabase.rawQuery("SELECT NAME FROM MyData", new 
    if (cursor.getCount() == 0) {
    } else {
        while (cursor.moveToNext()) {
    Object[] mStringArray = listItem.toArray();
    Fragment fragment = new AFragment();
    Bundle args = new Bundle();
    args.putString(AFragment.ARG_OBJECT, (String)mStringArray[i]);
    return fragment;

In the SwipeNav Activity, I used below to get value

if (getIntent().hasExtra(ListNavAdapter.ID_EXTRA)){
     String myInt = getIntent().getStringExtra(ListNavAdapter.ID_EXTRA);

     listSwipePagerAdapter = new ListSwipePagerAdapter(getSupportFragmentManager(),this);
    viewPager = (ViewPager) findViewById(R.id.pager);

Your issue appears to be that you are using l, expecting it to be the id. Unless a CursorAdapter is used it will be the position (the same as the 3rd parameter passed except long).

  • that is if you click on Letter you will pass 0 via the intent, click on Number and it will pass 1 and if you click on Word it will pass 2.

What you want to pass is the value of the clicked view (Letter Number or Word) and then use that to SELECT the respective rows.

  • You will never be able to reliably get an id as no such value is available in the ArrayList.

Therefore instead of intent.putExtra(ID_EXTRA, String.valueOf(l)); you want

intent.putExtra(ID_EXTRA, ((String)adapterView.getItem(i)));

or alternately

intent.putExtra(ID_EXTRA,((TextView) view).getText().toString());

Noting that the value from the list i.e the distinct values of the Header column (Letter, Number or Word according to the sample data).

To then get the values you want you would need a query, in the SwipeNav activity, such as


  • where the_value_from_ID_EXTRA would be replaced with the value extracted from the intent extras with the key ID_EXTRA that was passed to the SwipeNav activity.

  • Note the above code is in-principle code, it has not been tested or run and may therefore have some errors.

  • 1
Reply Report
      • 2
    • Thank You Sir for helping me. Sorry Sir for being late response. I have used ((String)adapterView.getItemAtPosition(i))); in ListNavAdapter. But when I click on item app terminates. I added SwipeNav Activity in the question. here in the line int foo = Integer.parseInt(myInt); shows java.lang.NumberFormatException: Invalid int. in the Adapter I used String myString=ListNavAdapter.ID_EXTRA; int foo=Integer.parseInt(myString); "SELECT NAME FROM MyData WHERE HEADER="+foo
    • When you get the Item you are getting one of the values Letter, Number or Word. They cannot be parsed into an int. Hence the NumberFormatException. Just use "SELECT NAME FROM MyData WHERE HEADER='" + myInt + "'" (note that = is followed by a single quote and then the double quote the last bit is double quote, single quote double quote (so Letter, Number or Word is treated as a literal value rather than a column name)).