|
||
|
|||
|
Hello,
I have essentially a preferences window with a bunch of boolean checkboxes. In another class, I need to check the status of these checkboxes (checked or unchecked), but I don't know how to do that since I can't make another instance of the class (as the boolean values wouldn't reflect those of the preferences runner class). Any help with this would be much appreciated! thanks!
|
|
|||
|
Quote:
Checkboxes c = new Checkboxes(); c.getStatus(); but in order to use these getters , i'd have to make a new instance like i did above, which wouldn't reflect their state in the other window. How can I pass this status to other classes? |
|
||||
|
java Code:
public class TheOtherClass { private final Checkboxes checkers; public TheOtherClass(CheckBoxes c){ this.checkers = c; } public void doCheck(){ checkers.getStatus();/// } } |
|
||||
|
Quote:
Java Code
class prefWindow {
// Define bunch of checkboxes
mCheckbox cb1 = ...
// Get the status of our cb1
public boolean get_cb1() {
return cb1.getStatus();
}
..
|
|
|||
|
Quote:
Java Code
public class Checkbox extends ListActivity {
/** Called when the activity is first created. */
private CheckBoxifiedTextListAdapter cbla;
// Create CheckBox List Adapter, cbla
private String[] items = {"Restaurants","Pizza", "Coffee Houses", "Bakeries", "Grocers", "Caterers/Chefs","Other" };
// Array of string we want to display in our list
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.checkbox);
cbla = new CheckBoxifiedTextListAdapter(this);
for(int k=0; k<items.length; k++)
{
cbla.addItem(new CheckBoxes(items[k], false));
}
// Display it
setListAdapter(cbla);
}
Last edited by michaelz; 21-07-2010 at 12:45 AM. |
|
||||
|
If the checkboxes are in prefWindow, the only way to access them is by having a reference to prefWindow. You wouldn't need to create a new instance. You would need a way to get a reference. Passing references is pretty common. What problem is there in your program?
Is prefWindow a singleton? IE there is only ever one instance at a time? Have a static getRef() method to return a reference to it. |
|
|||
|
Quote:
|
|
||||
|
You don't need to make all the variables and methods static. If you use the Singleton pattern, you only need a static varible to hold a reference to the one instance of the class and a static method to return that reference. The rest of the class would not be static.
Quote:
|
|
|||
|
so i did
Java Code
private static CheckBoxifiedTextListAdapter cbla; Java Code
public static getCbla()
{
return cbla;
}
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| HTTP Status 500 - | mqt | What's Wrong With My Code? | 3 | 06-04-2010 06:09 AM |
| how to delete record from checking checkbox value. | -_- | JavaServer Pages: JSP & JSTL | 2 | 12-03-2010 11:09 AM |
| Need java code to know the browser status | newnewgen | Java Theory & Questions | 2 | 09-01-2010 03:39 AM |
| how to delete record based on checkbox selected checkbox | -_- | JavaServer Pages: JSP & JSTL | 0 | 16-12-2009 01:26 AM |
| setEnabled causing checkbox to deselect | dewboy3d | AWT / Java Swing | 3 | 21-05-2009 04:36 PM |
|
100 most searched terms
Search Cloud
|
| actionlistener actionlistener in java addactionlistener addactionlister arraylist value into hash buffered read two integer value in java create an abstract class called shape with abstract methods+java double to integer double to integer in java double to integer java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread main java.lang.outofmemoryerror java heap space in eclipse format double java get mouse position java how to convert list to map in java how to format doubles in java how to make a calculator in jframe using jcreator http://www.javaprogrammingforums.com/object-oriented-programming/3713-limiting-decimal-places-double.html iphone java java actionlistener java cos java deallocate java double format java double to int java format double java forum java forums java get mouse position java heap size exception java jbutton java nextline() java program to find dimensions of a room java programming codes using astirisks java programming forum java programming forums java.lang.outofmemoryerror: java heap space java.lang.reflect.invocationtargetexception jbutton actionlistener jbutton with key enter jtable questions in java jtext bold jtextarea font jxl.read.biff.biffexception: unable to recognize ole stream kilowatts java program mean value decimal double java oops java assignments programmer forum smack api messagelistener two dimensional arraylist in java |