Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old December 2nd, 2012, 11:17 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2012
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Code not working. Please find error

this is my activity code:

package com.pal.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class DialogActivity extends Activity {

CharSequence[] items = {"Google","Microsoft","Yahoo"};

boolean[] itemschecked = new boolean[items.length];
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button btn = (Button) findViewById(R.id.btn_dialog);
btn.setOnClickListener(new View.OnClickListener() {


@SuppressWarnings("deprecation")
public void onClick(View v) {
// TODO Auto-generated method stub
showDialog(0);

}
});
}


protected Dialog onCreateDialog(int d){
switch(d) {
case 1:
return new AlertDialog.Builder(this)
.setIcon(R.drawable.ic_launcher)
.setTitle("This is a dialog")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub

Toast.makeText(getBaseContext(), "Ok Clicked", Toast.LENGTH_SHORT).show();

}
})

.setNegativeButton("Cance", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), "Cancel Clicked", Toast.LENGTH_SHORT).show();

}
})

.setMultiChoiceItems(items, itemschecked, new DialogInterface.OnMultiChoiceClickListener() {

public void onClick(DialogInterface dialog, int which, boolean isChecked) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), items[which] + (isChecked ? "checked!" : "unchecked!"), Toast.LENGTH_SHORT).show();
}

}).create();

}
return null;

}
}

Advertisements
pallavi1811 is offline  
Reply With Quote
sponsored links
Old December 2nd, 2012, 02:35 PM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,935
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts
Default

Please put your code inside either [code] or [high] tags.

Also, you haven't given near enough information for us to go on. "doesn't work" is too vague. What doesn't work about it? Does it throw an Exception? If it does, please provide a copy of the log cat output. If no exception is thrown, but it just doesn't do what is intended, well then, you need to tell us what exactly it is you are trying to do and what your app is doing instead.
__________________
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
Old December 3rd, 2012, 10:39 AM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jul 2012
Posts: 4
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI
I have created a button. On click of that button it should show me a dialog box. Clicking on button doesn't do anything. In the logs also i am not getting any error or anything.
pallavi1811 is offline  
Reply With Quote
Old December 3rd, 2012, 11:24 AM   #4 (permalink)
Junior Member
 
Join Date: May 2012
Posts: 27
 
Device(s): Nexus 7 (Android 4.2.1), Samsung Galaxy Mini (Android 2.3.6)
Carrier: Not Provided

Thanks: 1
Thanked 2 Times in 2 Posts
Default

Hi

Shouldn't you use the same id in onCreateDialog as in showDialog? You use "0" in showDialog but expect "1" in onCreateDialog.
myrecek is offline  
Reply With Quote
Reply
Tags
code


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:07 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.