-1
我有兩個Radiobutton和一個RadioButton點擊我想隱藏editfield,所以請任何人都可以幫助我。 謝謝,提前。在Radiobutton上隱藏EditField點擊黑莓
我有兩個Radiobutton和一個RadioButton點擊我想隱藏editfield,所以請任何人都可以幫助我。 謝謝,提前。在Radiobutton上隱藏EditField點擊黑莓
也許你可以嘗試使用管理刪除和添加字段。試試:
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public final class MyScreen extends MainScreen {
private BasicEditField bef = new BasicEditField();
private VerticalFieldManager manager = new VerticalFieldManager();
private RadioButtonGroup rbg = new RadioButtonGroup();
public MyScreen() {
setTitle("Hide Control Demo");
manager.add(bef);
add(manager);
RadioButtonField rbf1 = new RadioButtonField("Option 1", rbg, true);
RadioButtonField rbf2 = new RadioButtonField("Option 2", rbg, false);
add(rbf1);
add(rbf2);
rbf2.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (bef.getManager() != null && rbg.getSelectedIndex() == 1) {
manager.delete(bef);
System.out.println("Option 2 Selected");
}
}
});
}
}
試試這個它會工作
package com.hb;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Startup extends UiApplication{
public static void main(String[] args) {
Startup start=new Startup();
start.enterEventDispatcher();
}
public Startup() {
pushScreen(new screen());
}
}
class screen extends MainScreen implements FieldChangeListener
{
RadioButtonField field1,field2;
private EditField edit1;
private VerticalFieldManager edit_mgr=null;
public screen() {
HorizontalFieldManager hr=new HorizontalFieldManager();
RadioButtonGroup g=new RadioButtonGroup();
field1=new RadioButtonField("edit", g,true);
field1.setChangeListener(this);
hr.add(field1);
field2=new RadioButtonField("no edit", g,false);
field2.setChangeListener(this);
hr.add(field2);
add(hr);
edit_mgr=new VerticalFieldManager();
edit1=new EditField();
edit1.setEditable(true);
edit_mgr.add(edit1);
add(edit_mgr);
}
public void fieldChanged(Field field, int context) {
if(field==field1){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(true);
}
}else if(field==field2){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(false);
}
}
}
}
非常感謝!這很棒 – Hetal
歡迎:) –