If you change your code in a few places, it should work. (It worked
for me :))
I have demarked the code changes with
//======== START==== and //======= END ====
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Handler handler=new Handler();
//====== START ====
// 1. I assume you have a TextView defined in your layout.main
file.
// 2. Make sure you have android:id set e.g. <TextView
android:id="@+id/tview"
TextView statusField = (TextView) findViewById(R.id.tview);
//====== END ======
F thread=new F(this,statusField,handler);
thread.start();
}
}
class F extends Thread{
Context context;
TextView statusField;
Handler handler;
String voto;
F(Context context,TextView statusField,Handler handler)
{this.context=context;this.statusField=statusField;this.handler=handler;}
public void run()
{
final CharSequence[] items = {"Ottimo", "Buono",
"Sufficiente","Insufficiente"};
String voto="";
handler.post(new Runnable(){public void run(){
AlertDialog.Builder builder = new
AlertDialog.Builder(context);
builder.setTitle("Pick a color");
builder.setSingleChoiceItems(items, -1,
new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface
dialog, int item) {
Toast.makeText
(context.getApplicationContext(), items
[item], Toast.LENGTH_SHORT).show();
//======== START =======
dialog.cancel();
statusField.setText(items[item]);
//========= END =========
}
});
AlertDialog alert = builder.create();
alert.show();
}});
//statusField.setText(voto); //REMOVE
}
}
Hope this helps,
Balwinder Kaur
Open Source Development Center
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.
On Aug 4, 5:48 am, Lorenz <[email protected]> wrote:
> Hi,
> I have a problem, I want to create an Alert Builder in a thread
> started by tha main activity.This Builder should be a multiple
> choiche.
> The code is:
>
> public class C extends Activity {
>
> private PrintWriter savedpoint;
> private Context context = this;
> private TextView statusField;
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
> Handler handler=new Handler();
>
> F thread=new F(this,statusField,handler);
> thread.start();
>
> }
>
> }
>
> class F extends Thread{
>
> Context context;
> TextView statusField;
> Handler handler;
> String voto;
>
> F(Context context,TextView statusField,Handler handler)
> {this.context=context;this.statusField=statusField;this.handler=handler;}
> public void run()
> {
>
> final CharSequence[] items = {"Ottimo", "Buono",
> "Sufficiente","Insufficiente"};
>
> String voto="";
>
> handler.post(new Runnable(){public void run(){
> AlertDialog.Builder builder = new
> AlertDialog.Builder(context);
> builder.setTitle("Pick a color");
> builder.setSingleChoiceItems(items, -1, new
> DialogInterface.OnClickListener() {
> public void onClick(DialogInterface
> dialog, int item) {
>
> Toast.makeText(context.getApplicationContext(), items
> [item], Toast.LENGTH_SHORT).show();
>
> }
> });
> AlertDialog alert = builder.create();
> alert.show();
>
> }});
>
> statusField.setText(voto);
>
> }
>
> }
>
> Problem 1: what can I do for doing some actions when a user select one
> of the alert choiches?
> Problem 2: It seems that the code doesn't stop when the alert dialog
> appears but still run, as a matter of fact the statusField is empty
> when appears.
> If nothing is possible to do Is there any other way to obtain
> something like this working?
> THanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---