1

I would like to upload files to ftp server by choosing account using Alert Dialog. The Alert Dialog show when the Activity starts. I know how to create Alert Dialog when activity starts. But, i don't know get the values from database within the Alert Dialog. I've used SQLiteOpenHelper for database and using ContentValues for store the records. How can i choose this in Alert Dialog? Anyone help me to find out that? Thanks in Advance.

1 Answers1

0

Try this stuff,

Fetch the database values in an String array.

             Cursor c = mydb.readFromLogin();
             final String[] array = new String[c.getCount()];
             if(c.getCount() > 0){
                c.moveToFirst();
                for (int i = 0; i < c.getCount() - 1; i++) {
                    array[i] = c.getString(0);
                    c.moveToNext();
                }           
            }
        Builder mbBuilder = new AlertDialog.Builder(LoginActivity.this);
        mbBuilder.setItems(array, new DialogInterface.OnClickListener() 
        {
            @Override
            public void onClick(DialogInterface dialog, int which) 
            {
                if(which == 0)
                {
                    Toast.makeText(getApplicationContext(), array[which], Toast.LENGTH_SHORT).show();
                }
                else if(which == 1)
                {
                        Toast.makeText(getApplicationContext(), array[which], Toast.LENGTH_SHORT).show();
                }
            }
        });
        mbBuilder.setNegativeButton("Cancel", null);
        mbBuilder.create().show();
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • Now, check my updated Answer how to fetch the data from database and set in the Alert Dialog. – Lalit Poptani Sep 23 '11 at 13:43
  • @Praveen please change this question to a question that is "How to show sqlite database values in AlertDialog". Because your question has nothing to do with FTP server here. – Lalit Poptani Oct 03 '11 at 13:38