How to dismiss the single select dialog in AlertDialog

by mercury xu » Sun, 15 Mar 2009 13:13:01 GMT


Sponsored Links
 i Vincent

That a good idea , as we know, if we build an alterDlg need following
code

//modify by mercury xu 20090314 in the new sdk
//they don't support this function as showAlert!

new AlertDialog.Builder(loginScreen.this)
.setTitle("Login Data")
.setMessage("Login :" + usrTxt + "\n"+ "PassWords : " + pwdTxt)
.setIcon(R.drawable.icon)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.show();

maybe you can try to change the setPositiveButton and setNegativeButton
as Not visible or comment them, and add following code for keyup or keydown
founction.

OnClickListener as setResult(RESULT_OK);
finish();

you can get some useful infomation from
http://developer.android.com/reference/android/app/AlertDialog.html.

boolean
onKeyDown<http://developer.android.com/reference/android/app/AlertDialog.html#onKeyDown%28int,%20android.view.KeyEvent%29>(int
keyCode,
KeyEvent<http://developer.android.com/reference/android/view/KeyEvent.html>event)
A
key was pressed down.
boolean
onKeyUp<http://developer.android.com/reference/android/app/AlertDialog.html#onKeyUp%28int,%20android.view.KeyEvent%29>(int
keyCode,
KeyEvent<http://developer.android.com/reference/android/view/KeyEvent.html>event)
A
key was released.

those two founction I hope that is your need.

Wish good luck and best regards!

Mercury







2009/3/15 vincent Kor <kor.vinc...@gmail.com>


--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. SqliteOpenHelper db adapter design question

Hi all,

I am writing an app that has a single database file with 3 tables
( AudioTable, PeopleMap, ImageTable)
and am looking at 2 design alternatives:

1. A -single- database adapter (myDBAdapter.java) which
uses a database helper class that extends SQLiteOpenHelper.
The adapter class has separate methods for accessing and updating rows
in each of the 3 tables.
ie. insertAudio()
   insertPeople()
   insertImage()


2.  3 different database adapters for each table all using the same db
file..
1. audioDBAdapter.java,
2. peopleDBAdapter.java,
3. imageDBAdapter.java)
Each adapter uses it's own db helper class (extending
SQLiteOpenHelper)

While option 2 offers better encapsulation of the 3 classes (and
corresponding data),
I'm wondering if there couldbe a performance overhead or does the
SQLiteOpenHelper implementation handle this without much overhead ?

Or is there some other way I can get better encapsulation with option
1. something similar
to the way the Contacts Provider nicely allows for separate instances
of
Contacts.People, Contacts.Phones, Contacts.Settings, etc.

--~--~---------~--~----~------------~-------~--~----~

2. Basic java threading problems, code inside

I understand the concept of threads, and it almost seems like I
understand how to implement them.  This code executes properly until I
press the back button (to close), and then gives a "This application
has stopped unexpectedly.  Please try again."  Well duh, I closed it!

Heres the code Im using:

(It is a slightly modified version of the example provided
here: http://www.helloandroid.com/node/243

using the modifications I found
here: 
http://stackoverflow.com/questions/680180/where-to-stop-destroy-threads-in-android-service-class
)

The import Pi class comes from this website, its just an arbitrary
class that will perform a long calculation to show the example

http://blog.taragana.com/index.php/archive/calculate-pi-to-arbitrary-precision-sample-java-code/

/*************************************************/
package com.example;

import com.example.Pi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AndroidThreads extends Activity implements Runnable {

    private String pi_string;
    private TextView tv;
    private ProgressDialog pd;
    private volatile Thread runner;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        mp = MediaPlayer.create(getBaseContext(),
R.raw.camera_click); //this is using the slow.mp3 resource
        tv = (TextView) this.findViewById(R.id.box);
        tv.setText("Press submit to start calculation");

                Button submit = (Button) findViewById(R.id.submit_btn);
        submit.setOnClickListener(new OnClickListener(){
                public void onClick(View v){
                        startThread();
                }
        });
    }

    public synchronized void startThread(){
      if(runner == null){
        pd = ProgressDialog.show(this, "Working..", "Calculating Pi",
true, false);
        runner = new Thread(this);
        runner.start();
      }
    }

    public synchronized void stopThread(){
      if(runner != null){
        Thread moribund = runner;
        runner = null;
        moribund.interrupt();
      }
    }

    public void run(){
          pi_string = Pi.computePi(800).toString();
          handler.sendEmptyMessage(0);
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            pd.dismiss();
            tv.setText(pi_string);
        }
    };
}
/*************************************************/

So like I said, this does everything I want it to do, except... it
gives the crash error when I exit the program.

*So what I need to know is why is it crashing, and how can I fix it?*

It seems to me like the threads aren't all finishing properly, so I
tried putting the stopThread() function into the onStop() and onDestroy
() overrides, but that didn't seem to make a difference.  Appreciate
any input!

-kevin

--~--~---------~--~----~------------~-------~--~----~

3. Can an android netbook program be migrated smoothly to an android smartphone device?

4. MapActivity resolution problem

5. using getAttributeIntValue in a custom item

6. How to open the soft keyboard by code

7. Custom Tabs