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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:39:14+00:00 2026-05-20T09:39:14+00:00

I am currently developing an app where the main screen hasn’t got an actual

  • 0

I am currently developing an app where the main screen hasn’t got an actual view as in setContentView(R.layout.myScreen); is used. Instead it uses an XML file which just details a textview which is assigned to an list adapter and fill with data from the database.

Below is the XML file that is used

    <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:myapp="http://schemas.android.com/apk/res/com.BoardiesITSolutions.PasswordManager"
            android:id="@+id/showLogin"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="10dp"
            android:textSize="16dp">
    </TextView>

And below is the code where data is added to the textview list adapter

public class ShowLogins extends ListActivity {

String LOGINS[] = null;
String company = null;
String longClickCompany;

String companyName = "";
String companyURL = "";
String companyUsername = "";
String companyPassword = "";
Boolean passwordEnabled;
public void onCreate(Bundle savedInstanceState)
{
    SharedPreferences settings = getSharedPreferences("prefs", 0);

    boolean enablePassword = settings.getBoolean("enablePassword", false);
    boolean loggedIn = settings.getBoolean("loggedIn", false);
    super.onCreate(savedInstanceState);
    if (loggedIn)
    {
        passwordEnabled = settings.getBoolean("enablePassword", false);
        setContentView(R.layout.show_login);

    //registerForContextMenu(getListView());


    addToArray();

    setListAdapter(new ArrayAdapter<String>(this, R.id.showLoginBox, LOGINS));

    //ListView lv = getListView();
    ListView lv = (ListView)findViewById(R.id.show_list_view);
    //View myView = findViewById(R.layout.advert);
    //lv.addView(myView);

    lv.setTextFilterEnabled(true);

    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view,
                int position, long id) {
            longClickCompany = ((TextView) view).getText().toString();
            return false;
        }
    });

    lv.setOnItemClickListener(new OnItemClickListener() {


        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            company = ((TextView) view).getText().toString();
            StringTokenizer st = new StringTokenizer(company, "\n");
            String companyName = st.nextToken();
            String username = st.nextToken();
            prepareLoadingWebsite(companyName, username);
        }
    });
    }
    else
    {
        Intent intent = new Intent(ShowLogins.this, SplashScreen.class);
        startActivity(intent);
    }
}

private void addToArray()
{
    int totalRows = 0;
    int added = 0;
    int arrayField = 0;
    SQLiteDatabase myDB = null;
    Cursor c = null;
    Cursor count = null;
    try
    {
        myDB = this.openOrCreateDatabase("PasswordManager", MODE_PRIVATE, null);
        count = myDB.rawQuery("SELECT COUNT(*) FROM PASSWORD", null);
        if (count.moveToNext())
        {
            totalRows = count.getInt(0);
        }
        LOGINS = new String[totalRows];

        c = myDB.rawQuery("SELECT * FROM password ORDER BY pas_company ASC", null);

        while(arrayField <=2 && c.moveToPosition(added))
        {
            LOGINS[added] = c.getString(1) + "\n" + c.getString(3);
            added++;
        }

        if (totalRows == 0)
        {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("No login records have been found.\n\n Press menu > New login to add a record")
                .setCancelable(false)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
            AlertDialog alert = builder.create();
            alert.show();
        }
        else
        {
            setListAdapter(new ArrayAdapter<String>(this, R.layout.show_login, LOGINS));

            ListView lv = getListView();
            lv.setTextFilterEnabled(true);
        }

    }
    catch (SQLiteException ex)
    {
        Log.d("Database Error", ex.toString());
    }
    finally
    {
        myDB.close();
        c.close();
        count.close();
    }
}
  • 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-20T09:39:14+00:00Added an answer on May 20, 2026 at 9:39 am

    When you use ListActivity you get a content layout specified by the system if you don’t specify one yourself. Create your own layout for the activity that looks something like this:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ListView android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />
        <!-- Ad view goes here with layout_width="match_parent" and layout_height="wrap_content" -->
    </LinearLayout>
    

    Set it using setContentView as usual. ListActivity needs a ListView with id @android:id/list that it can find if you’re using a custom layout. The height=0, weight=1 configuration of the list will give it all remaining space in the layout after the ad’s height is measured.

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

Sidebar

Related Questions

I have a search form in an app I'm currently developing, and I would
We are currently developing a server whereby a client requests interest in changes to
I was currently developing a desktop application in C# using mono and testing in
I am currently developing an approval routing WCF service that will allow an user
I am currently developing a Rails application using a database that was designed before
I'm currently developing for a handheld device running Windows XP Professional (not Tablet PC
I'm currently developing a PHP application that's using an Access database as a backend.
I'm currently developing an application that is comprised of five separate executables that communicate
We're currently developing a new piece of hand-held software. I cant discuss the nature
I'm currently developing (another) Open Source CMS in PHP and I'd like to use

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.