Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:18:22+00:00 2026-05-29T09:18:22+00:00

I have gone through several tutorials on fragments and I can’t get my queries

  • 0

I have gone through several tutorials on fragments and I can’t get my queries to display in a List Fragment.

Below are my original classes that need converting for use in a fragment activity. My QueryDisplay class has so much in it, I don’t know what to remove from it and where to put it to get it working. Mainly, I don’t know how to call my ListView Class in the below Fragment Activity.

Thank-Your for your help in advance. Code would be very helpful too!!

Here is the ListActivity that queries a SQLite database And below id the fragment class:

public class QueryDisplay extends ListActivity {

protected TextView activityTitle;

boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;

String extStorageDirectory = Environment.getExternalStorageDirectory()
    .toString();
File dbfile = new File(extStorageDirectory
    + "/myco/myapp/dB/myapp.db");
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

private static final String QUERY_KEY = "QUERY_KEY";
private static final String QUERY_ORDER = "QUERY_ORDER";

// private static final String NI = "NI";

/**
 * -- Called when the activity is first created
 * ===================================================================
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle extras = getIntent().getExtras();
setContentView(R.layout.list_view2);

/**
 * Populate the ActionBar----------------------------------
 */
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
getActionBar().setBackgroundDrawable(
    getResources().getDrawable(R.drawable.actionbar_bg));
String sT = getIntent().getStringExtra("KEY_SUBTITLE");
actionBar.setSubtitle(sT);

/**
 * Get the query string from last activity and pass it to this
 * activity-----------------------------------------------------
 */
String q = null;
if (extras != null) {
    q = extras.getString(QUERY_KEY);
}
loadQuery(q);
}

/**
 * -- DB QUERY STUFF
 * ===============================================================>
 * 
 * Run the initial query from the previous activity---------------
 */
public void loadQuery(String q) {

if (Environment.getExternalStorageState().equals(
    Environment.MEDIA_MOUNTED)) {

    String qO = getIntent().getStringExtra("QUERY_ORDER");

    Cursor c = db.rawQuery(q + " ORDER BY `_id` " + qO, null);
    setListAdapter(new QueryAdapter(this, c));
    db.close();

} else {
    Alerts.sdCardMissing(this);
}
}

/**
 * The Query Adaptor --------------------------------------------
 */

private class QueryAdapter extends CursorAdapter {

public QueryAdapter(Context context, Cursor c) {
    super(context, c);
    LayoutInflater.from(context);
}

@Override
public void bindView(View v, Context context, final Cursor c) {

    int tvLabel = c.getColumnIndexOrThrow("label");
    String label = c.getString(tvLabel);
    final TextView labelTxt = (TextView) v.findViewById(R.id.label);

    if (labelTxt != null) {
    labelTxt.setText("(" + label + ")");
    }

    int tvTitle = c.getColumnIndexOrThrow("title");
    final String title = c.getString(tvTitle);
    TextView titleTxt = (TextView) v.findViewById(R.id.listTitle);

    if (titleTxt != null) {
    titleTxt.setText(title);
    }

    int tvDescription = c.getColumnIndexOrThrow("description");
    String description = c.getString(tvDescription);
    TextView descriptionTxt = (TextView) v.findViewById(R.id.caption);

    if (descriptionTxt != null) {
    descriptionTxt.setText(description);
    }

    int tvDate = c.getColumnIndexOrThrow("date");
    String date = c.getString(tvDate);
    TextView dateTxt = (TextView) v.findViewById(R.id.dateAdded);

    if (dateTxt != null) {
    dateTxt.setText(date);
    }

    int tvGoto = c.getColumnIndexOrThrow("gotoURL");
    final String gotoURL = c.getString(tvGoto);
    TextView gotoTxt = (TextView) v.findViewById(R.id.dummy);

    if (gotoTxt != null) {
    gotoTxt.setText(gotoURL);
    }

    gotoTxt.setVisibility(View.GONE);
    v.setTag(gotoURL);

    final ListView lv = getListView();
    lv.setEnabled(true);
    lv.setClickable(true);

    lv.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View v, int arg2,
        long arg3) {

        // -- Set the domain name in the strings.xml file once the
        // DNS is established for the website.
        String mDomain = getResources().getString(R.string.domain);

        String url = "";
        url = mDomain + (String) v.getTag();

        int nI = c.getColumnIndexOrThrow("intent");
        String intent = c.getString(nI);
        Class<?> nIntent = null;
        try {
        nIntent = Class
            .forName("com.myco.myapp.utili."
                + intent);
        } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }

        int tvTitle = c.getColumnIndexOrThrow("title");
        String title = c.getString(tvTitle);

        int tvLabel = c.getColumnIndexOrThrow("label");
        String label = c.getString(tvLabel);

        String queryKey = "SELECT * FROM " + label;
        c.close();
        db.close();

        Intent i = new Intent(QueryDisplay.this, nIntent);
        i.putExtra("QUERY_KEY", queryKey);
        i.putExtra("KEY_URL", url);

        Log.e("tag", url);

        i.putExtra("KEY_SUBTITLE", title);
        i.putExtra("KEY_LABEL", label);
        i.putExtra("KEY_INTENT", intent);
        i.putExtra("QUERY_ORDER", "ASC");
        i.putExtra("KEY_YPOS", "0.0");
        QueryDisplay.this.startActivity(i);
    }
    });
}

/**
 * Inflate and returned the query to the view
 * --------------------------------
 */
@Override
public View newView(Context context, Cursor c, ViewGroup parent) {
    final View v = LayoutInflater.from(context).inflate(
        R.layout.list_item, parent, false);
    return v;
}
}
}

QueryDisplayFRAGMENT Class:

public class QueryDisplayFRAGMENT extends ListFragment {
boolean mDualPane;
int mCurCheckPosition = 0;

@Override
public void onActivityCreated(Bundle savedState) {
super.onActivityCreated(savedState);

      ****What do I do/put here to get the above list to show in this list fragment???

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:18:23+00:00Added an answer on May 29, 2026 at 9:18 am

    Try something like this:

       public class QueryDisplayFRAGMENT extends ListFragment {
        boolean mDualPane;
        int mCurCheckPosition = 0;
        protected TextView activityTitle;
    
        boolean mExternalStorageAvailable = false;
        boolean mExternalStorageWriteable = false;
    
        String extStorageDirectory = Environment.getExternalStorageDirectory()
            .toString();
        File dbfile = new File(extStorageDirectory
            + "/myco/myapp/dB/myapp.db");
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
    
        private static final String QUERY_KEY = "QUERY_KEY";
        private static final String QUERY_ORDER = "QUERY_ORDER";
    
        private View layout;
    
        @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {
                layout = inflater.inflate(R.layout.list_view2, null);
                return layout;
    
            }
    
        @Override
        public void onActivityCreated(Bundle savedState) {
    
            /**
         * Populate the ActionBar----------------------------------
         */
        ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        getActionBar().setBackgroundDrawable(
            getResources().getDrawable(R.drawable.actionbar_bg));
        String sT = getIntent().getStringExtra("KEY_SUBTITLE");
        actionBar.setSubtitle(sT);
    
        /**
         * Get the query string from last activity and pass it to this
         * activity-----------------------------------------------------
         */
        String q = null;
        if (extras != null) {
            q = extras.getString(QUERY_KEY);
        }
        loadQuery(q);
    
        super.onActivityCreated(savedState);
        }
    
    public void loadQuery(String q) {
    
    if (Environment.getExternalStorageState().equals(
        Environment.MEDIA_MOUNTED)) {
    
        String qO = getIntent().getStringExtra("QUERY_ORDER");
    
        Cursor c = db.rawQuery(q + " ORDER BY `_id` " + qO, null);
        setListAdapter(new QueryAdapter(getActivity(), c));
        db.close();
    
    } else {
        Alerts.sdCardMissing(getActivity());
    }
    }
        }
    

    If you have problems tell me about it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting to learn python. I have gone through several tutorials and now
Have gone through hibernate api specification on FlushMode but didn't get the exact difference.
While attempting to build a website, i have gone through many online tutorials. Thanks
I have gone through the several samples in the web.I understood to protect software
I've already created my models and have gone through several migrations. Now, I want
I have gone through most of the code here and tried several ways to
I have gone through the below links Problem with synchronizing on String objects? and
I have gone through their developer guide but haven't been able to find a
I have gone through different questions/articles on Message Brokers and ESBs(Even on stackoverflow). Still
I have gone through following question. Convert NSString to NSDictionary It is something different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.