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 7885399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:03:32+00:00 2026-06-03T05:03:32+00:00

The title may be bit confusing but here is what I am facing I

  • 0

The title may be bit confusing but here is what I am facing

I have a class:

    public abstract class BaseFragmentActivity<T> extends FragmentActivity {
    static final int PROGRESS_DIALOG = 0;
    Dialog progessDialog;

    public abstract void displayData(T output);

    @Override
    protected Dialog onCreateDialog(int id) {
        if (id == PROGRESS_DIALOG) {
            ProgressDialog progressDialog = ProgressDialog.show(this, "",
                    "Loading. Please wait...", true);
            progessDialog = progressDialog;
        }

        return progessDialog;
    }

    class PerformOPTask extends AsyncTask<Void, String, T> {
        // connector=new JSONConnector();
        Connector connector;
        String curUrl;
        Class<T> clazz;

        PerformOPTask(String url, Class<T> curClazz) {
            //connector = new UnitTestConnector();
            connector = new JSONConnector();
            curUrl = url;
            clazz = curClazz;
        }

        @Override
        protected T doInBackground(Void... params) {

            return connector.getData(URLUtils.getFormattedUrl(curUrl),clazz);
        }

        @Override
        protected void onPostExecute(T output) {
            displayData(output);

        }
    }




}

Then I have a subclass as :

public abstract class BaseListFragmentActivity<T> extends BaseFragmentActivity<T> implements OnItemClickListener, OnClickListener{

    protected ListView mList;


    /** Called when the activity is first created. */
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.table_list);
        CommonUtil.getActionBarWithBackButton(this,getLayoutInflater());
        mList=(ListView)findViewById(R.id.table_list_listView);
        mList.setOnItemClickListener(this);

    }

    public void onBackABButtonPressed(View view) {
        finish();
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

    @Override
    public abstract void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3);


}

Now I am extending this class as below:

public class ListAccountsActivity<T> extends BaseListFragmentActivity<AccountData> {

    protected Acct[] mItems;
    private String[] mIcons;
    protected boolean displayHandledBySubClass=false;


    /** Called when the activity is first created. */
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);


        new PerformOPTask(getString(R.string.get_account),AccountData.class).execute();
        showDialog(PROGRESS_DIALOG);
        //.getData(URLUtils.getFormattedUrl(getString(R.string.get_account)),actData);




    }

    @Override
    public void onItemClick(AdapterView<?> lv, View view, int position, long id) {
        // super.onListItemClick(l, v, position, id);
        // Get the item that was clicked
        Acct account = (Acct) mList.getAdapter().getItem(position);
        Intent intent=new Intent(this,AccountDetailViewActivity.class);
        intent.putExtra("selectedAccount",account);
        startActivity(intent);
    }

    @Override
    public void displayData(AccountData output){


        if(displayHandledBySubClass){
            //handle display in subclass
            handleDisplayData(output);
        }
        else {
            Acct[] accountArray = new Acct[output.getAccount().size()];
            mItems = output.getAccount().toArray(accountArray);
            IWMArrayAdapter<Acct> adapter = new IWMArrayAdapter<Acct>(this, mItems);
            adapter.setIcons(mIcons);
            adapter.setArrowNeeded();
            //mList is superClassVariable
            mList.setAdapter(adapter);
            dismissDialog(PROGRESS_DIALOG);
            adapter.notifyDataSetChanged();
        }
    }

    public void handleDisplayData(T output){

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //Toast.makeText(this, "Tapped search", Toast.LENGTH_SHORT).show();
        super.onCreateOptionsMenu(menu);
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.list_servers_menu, menu);

        // Calling super after populating the menu is necessary here to ensure
        // that the
        // action bar helpers have a chance to handle this event.
        return true;
    }


}

My Question is can I make handleDisplayData generic in some way so that I can pass any type to it. What I am trying to do is to reuse logic in BaseListFragmentActivity as much as possible and handle the only task specific to ListAccountsActivity or its subclass in that class/subclass.

I hope my question is clear, Thanks for any help

  • 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-06-03T05:03:34+00:00Added an answer on June 3, 2026 at 5:03 am

    If I understand correctly, you want to be able to use type-specific methods from the base in the subclass, and for that you need to make everything generic:

    public abstract class GenericBase<T> { ... }
    public abstract class ExtendedGeneric<T> extends GenericBase<T> { ... }
    public class ExtendedGenericSub<T> extends ExtendedGeneric<T> { ... }
    

    Point being that if ExtendedGeneric extends GenericBase<DataOutput>, only methods of GenericBase<DataOutput> are accessible from ExtendedGeneric.

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

Sidebar

Related Questions

The title may be a bit vague, but here's my goal: I have a
Title may be confusing, but here's explanation with code. Based on some conditions, I
The title may have been confusing, but please let me explain: Currently when I
The title may be a bit ambiguous, but I couldn't think of a better
The title may be a little confusing, but I don't know how else to
The title may sound confusing but it actually isn't, I just didn't know how
Ok so the title may have been confusing so i have posted 2 code
I understand the title may sound confusing, but the goal is very clear: I
The title may sound a bit odd but I wanted to keep the title
This may not be explained the best but here it goes. I have a

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.