note-42 custom radioButton

本文介绍了一个简单的Android应用程序示例,展示了如何使用RadioGroup和RadioButton组件来创建一个搜索界面,用户可以选择搜索微博或搜索用户两个选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from:

http://blog.youkuaiyun.com/wanglong0537/article/details/6434728

 

 

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:orientation="vertical"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:background="@drawable/search_bg"  
    >  
<RadioGroup android:gravity="center"  
                    android:layout_gravity="bottom"   
                    android:orientation="horizontal"  
                    android:id="@+id/searchRadioGroup"   
                    android:layout_width="fill_parent"   
                    android:layout_height="wrap_content" >  
                    <RadioButton android:textSize="17.0sp"   
                        android:id="@+id/searchRadioShare"  
                        android:tag="radio_button0"   
                        android:text="搜索微博"  
                        android:layout_weight="1"   
                        style="@style/CustomLeftRadioBtn">  
                    </RadioButton>  
                    <RadioButton android:textSize="17.0sp"   
                        android:id="@+id/searchRadioUser"  
                        android:tag="radio_button1"  
                        android:text="搜索用户"  
                        android:layout_weight="1"   
                        style="@style/CustomRightRadioBtn">  
                    </RadioButton>  
</RadioGroup>  
</LinearLayout>  

 

 

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <mce:style name="CustomLeftRadioBtn"><!--  
        <item name="android:button">@null</item>   
        <item name="android:drawableLeft">@drawable/search_radio_1</item>  
        <item name="android:background">@drawable/search_left</item>  
            <item name="android:gravity">center_vertical</item>   
          
      
--></mce:style><style name="CustomLeftRadioBtn" mce_bogus="1">       <item name="android:button">@null</item>   
        <item name="android:drawableLeft">@drawable/search_radio_1</item>  
        <item name="android:background">@drawable/search_left</item>  
            <item name="android:gravity">center_vertical</item>   
          
    </style>  
     <mce:style name="CustomRightRadioBtn"><!--  
        <item name="android:button">@null</item>   
        <item name="android:drawableLeft">@drawable/search_radio_1</item>  
        <item name="android:background">@drawable/search_right</item>  
        <item name="android:gravity">center_vertical</item>   
      
--></mce:style><style name="CustomRightRadioBtn" mce_bogus="1">      <item name="android:button">@null</item>   
        <item name="android:drawableLeft">@drawable/search_radio_1</item>  
        <item name="android:background">@drawable/search_right</item>  
        <item name="android:gravity">center_vertical</item>   
    </style>  
</resources>   

 

 

import android.app.Activity;  
import android.os.Bundle;  
import android.view.View;  
import android.view.View.OnClickListener;  
import android.widget.Button;  
import android.widget.Toast;  
public class RadioButtonDemo extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
          
        Button searchRadioShare = (Button) findViewById(R.id.searchRadioShare);  
        Button searchRadioUser = (Button) findViewById(R.id.searchRadioUser);  
          
        searchRadioShare.setOnClickListener(l);  
        searchRadioUser.setOnClickListener(l);  
    }  
      
    private View.OnClickListener l = new OnClickListener(){  
        @Override  
        public void onClick(View v) {  
            if(v.getId()==R.id.searchRadioShare){  
                Toast.makeText(RadioButtonDemo.this, "搜索微博", Toast.LENGTH_LONG).show();  
            }else{  
                Toast.makeText(RadioButtonDemo.this, "搜索用户", Toast.LENGTH_LONG).show();  
            }  
              
        }  
          
    };  
}  

 

function varargout = advisor(varargin) % advisor Application M-file for advisor.fig % FIG = advisor launch advisor GUI. % advisor('callback_name', ...) invoke the named callback. % % ADVISOR Advanced Vehicle Simulator % % This function opens the first graphical user interface (GUI) into % the program ADVISOR. % % The ADVISOR program is designed to assist in testing different % vehicle configurations using standard and custom driving cycles or % test procedures. % % For help in running ADVISOR please use the help buttons found on % each user interface which links to the documentation pages. If you still % need help or have helpful suggestions for improvement please email: % advisor@nrel.gov % % Last Modified by GUIDE v2.0 21-Mar-2002 15:12:42 if nargin == 0 % LAUNCH GUI global vinf %----------------------------------------------------------- %if ADVISOR is running then don't start another one, just %bring the current ADVISOR figure to the top figure_tags={'advisor_figure';'input_figure';'execute_figure';'results_figure';... 'rw_results_figure';'parametric_results_figure';'j1711_results_figure';... 'city_hwy_results_figure';'ftp_results_figure'}; for i=1:size(figure_tags) if ~isempty(findobj('tag',figure_tags{i})) figure(findobj('tag',figure_tags{i})); return end end %------------------------------------------------------------- advisor('set_path') %-------------------------------------------------- %clear the workspace evalin('base','clear'); evalin('base','global vinf') %set units to 'us' if not defined if ~exist('vinf.units') vinf.units='us'; end hwait=waitbar(0,'loading startup figure'); try waitbar(.5) end %add some sound if user's system can play sound try load list_optionlist.mat; %loads list_optionlist and list_def if findstr(lower(list_def),'truck') [advisor_sound,fs]=wavread('truckwelcome.wav'); else [advisor_sound,fs]=wavread('advisor.wav'); end sound(advisor_sound,fs) end %--------------------------------------------------- fig = openfig(mfilename,'new'); %'reuse' wasn't working when SOC figure was up %fig = openfig(mfilename,'reuse'); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end %------------------------------------------------------- %adjust the figure appropriately [ver,date]=advisor_ver('info'); set(findobj('tag','advisor_figure'),'Name',[ver ' ' date]) %set the units radio buttons appropriately set(findobj('tag','metric_radiobutton'),'value',strcmp(vinf.units,'metric')) set(findobj('tag','us_radiobutton'),'value',strcmp(vinf.units,'us')) %set the optionlist popupmenu advisor('set_optionlist_popup') %set everything normalized and set the figure size and center it h=findobj('type','uicontrol'); g=findobj('type','axes'); set([h;g],'units','normalized') screensize=get(0,'screensize'); if screensize(3)<1024 uiwait(warndlg({'ADVISOR does not work well at resolutions lower than 1024x768. Please increase resolution or proceed with caution!'},... 'ADVISOR: Low Resolution Warning','modal')) end %test for large fonts and give warning if they are large. figh=figure('visible','off'); test_string='test string'; handle_text=text(0,0,test_string); set(handle_text,'units','pixels') extent=get(handle_text,'extent');% 0 -9 60 18 close(figh); if extent(3)>61 uiwait(warndlg({'ADVISOR does not work well with large fonts. Please change your display settings to small fonts or proceed with caution!'},... 'ADVISOR: Low Resolution Warning','modal')) end im_width=640;%this is the width of the image im_height=474; left=screensize(3)/2-im_width/2; bottom=screensize(4)/2-im_height/2; set(gcf,'position',[left bottom im_width im_height]);% set(gcf,'resize','off') %set the figure back on after everything is drawn set(gcf,'visible','on'); advisor_ver waitbar(1) close(hwait); %close the waitbar adv_dir=strrep(which('advisor'),'\advisor.m',''); imagedata = imread([adv_dir '\gui_graphics\Splash_Screen_car.jpg']); h=image(imagedata); set(h,'ButtonDownFcn','advisor(''play_movie'')'); advisor('play_movie') elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = Copyright_button_Callback(h, eventdata, handles, varargin) copyright % -------------------------------------------------------------------- function varargout = Start_button_Callback(h, eventdata, handles, varargin) global vinf close(gcbf); evalin('base','global vinf'); gui_input_open('defaults'); % -------------------------------------------------------------------- function varargout = edit_optionlist() edit_profiles % -------------------------------------------------------------------- function varargout = Profile_Popup_Callback(h, eventdata, handles, varargin) current_selection_str=gui_current_str('Profile_Popup'); if strcmp(current_selection_str,'edit list') advisor('edit_optionlist') return end global vinf vinf.optionlist.name=current_selection_str; load list_optionlist.mat list_def=current_selection_str; p=which('list_optionlist.mat'); save(p,'list_def','list_optionlist'); %--------------------------------------------------------------------- function varargout = set_optionlist_popup load list_optionlist.mat; %loads list_optionlist and list_def set(findobj('tag','Profile_Popup'),'string',list_optionlist) index=strmatch(list_def, list_optionlist, 'exact'); set(findobj('tag','Profile_Popup'),'value',index); global vinf vinf.optionlist.name=list_def; % -------------------------------------------------------------------- function varargout = Help_button_Callback(h, eventdata, handles, varargin) web(['file:\\\' which('advisor_doc.htm')],'-browser'); % -------------------------------------------------------------------- function varargout = Exit_button_Callback(h, eventdata, handles, varargin) close(gcbf) % -------------------------------------------------------------------- function varargout = list_popup_Callback(h, eventdata, handles, varargin) %---------------------------------------------------- function set_path() %------------------Add ADVISOR directories to the MATLAB path------------- % Add the appropriate paths based on where advisor.m is found with the which command (This % defines the main ADVISOR directory) % % NOTE: paths will only be added with the addpath command if they don't already exist. % If new directories were added to the path (using addpath), a 1 will be returned % otherwise a 0 will be returned. % % SetAdvisorPath can accept a comma separated list of arguments. The arguments should be % the name of an existing directory. Non-existing directories will not be created. % path_added=SetAdvisorPath; % external function that contains necessary path information %find out if user wants to save the path changes. if path_added==1 ButtonName=questdlg('The Matlab path has been updated with ADVISOR directories for this Matlab session. Would you like to save the new path for future Matlab sessions? Note: Using VisualDoc optimization requires the path to be saved. ', ... 'ADVISOR path setting', ... 'Yes','No','Yes'); switch ButtonName, case 'Yes', result=path2rc; %path2rc saves the current path to pathdef.m (Both are MATLAB files-- not ADVISOR files) if result==0 disp('ADVISOR Directories were successfully added to the Matlab Path. See Path browser for path information.'); else disp('Not successful. ADVISOR directories were not successfully saved in the Matlab Path.'); end case 'No', end % switch end; %if path_added=1; % -------------------------------------------------------------------- function varargout = Load_Results_Callback(h, eventdata, handles, varargin) global vinf if ~exist('varargin') % no user-specified filename provided [name, path]=uigetfile('*.mat'); %user input for mat name of saved simulation elseif isempty(varargin) [name, path]=uigetfile('*.mat'); %user input for mat name of saved simulation else % user-specified filename provided path_name=varargin{1}; % break argument into the path and filename parts idx=strfind(path_name,'\'); if isempty(idx) idx=strfind(path_name,'/'); end if isempty(idx) name=path_name; path=''; else name=path_name((max(idx)+1):end); path=path_name(1:max(idx)); end end %if no file is selected(ie. figure is cancelled) %then exit(or return) out of this function if name==0 return end evalin('base','clear all') evalin('base',['load ''', path, name,'''']); close(gcbf); global vinf; if strcmp(vinf.parametric.run,'off') ResultsFig; else parametric_gui; end %--------------------------------------------------------------------- function metric_radiobutton_Callback(h, eventdata, handles, varargin) global vinf vinf.units='metric'; set(findobj('tag','us_radiobutton'),'value',0); set(findobj('tag','metric_radiobutton'),'value',1); %--------------------------------------------------------------------- function us_radiobutton_Callback(h, eventdata, handles, varargin) global vinf vinf.units='us'; set(findobj('tag','metric_radiobutton'),'value',0); set(findobj('tag','us_radiobutton'),'value',1); %--------------------------------------------------------------------- function play_movie() try adv_dir=strrep(which('advisor'),'\advisor.m',''); imagenames={'car2truck001.gif'; 'car2truck002.gif'; 'car2truck003.gif'; 'car2truck004.gif'; 'car2truck005.gif'; 'car2truck006.gif'; 'car2truck007.gif'; 'car2truck008.gif'; 'car2truck009.gif'; 'car2truck010.gif'; 'car2truck011.gif'; 'car2truck012.gif'; 'car2truck013.gif'; 'car2truck014.gif'; 'car2truck015.gif'}; for i=1:length(imagenames) [X,map]=imread([adv_dir '\gui_graphics\' imagenames{i}]); M(i)=im2frame(X,map); end loc=[36 206 0 0]; N=[-2 1 1 1 1 1 1 1:15 15 15 15 15 15 15 15]; movie(M,N,8,loc) end function LoadVehicle(filename) % allows user to start ADVISOR with a specific saved vehicle other than the default if ~exist('filename') filename='PARALLEL_defaults_in'; end if evalin('base',['~exist(''',filename,'.m'')']) disp(['File ',filename,'.m not found.']) else global vinf vinf.units='us'; gui_input_open(filename) end return function LoadResults(filename) % allows user to start ADVISOR with a specific results file from the command line if exist('filename') if evalin('base',['~exist(''',filename,'.mat'')']) disp(['File ',filename,'.mat not found.']) else advisor('Load_Results_Callback',[],[],[],filename) end end return % Revision History % 041802:tm added call to SetAdvisorPath external function and removed common code from this file % 041802:tm added statements to the Load_Results_Callback function to allow the user to specify a % results file to load from the command line % 041802:tm added function to allow user to load a specific vehicle from the command line % 041802:tm added function to allow user to load a specific results file from the command line 怎么修改可以让advisor2002适配MATLAB2024a
08-09
/****************************************************************** Function : onRadioClickMatrix Date : 2016-05-03 10:53:09 Author : Parameter : Return : Desc : 选择启用/禁用模式 2016.2.26 ******************************************************************/ void MatrixTask::onRadioClickMatrix() { if (sender() == ui->matrixAll_radioButton) // 全矩阵 { if (ui->matrixAll_radioButton->isChecked()) { ui->matrixSingle_radioButton->setChecked(false); ui->matrixRow_radioButton->setChecked(false); ui->matrixColumn_radioButton->setChecked(false); ui->matrixChange_radioButton->setChecked(false); m_matrixID = MATRIX_ALL; } else { m_matrixID = -1; } } else if (sender() == ui->matrixSingle_radioButton) // 单点 { if (ui->matrixSingle_radioButton->isChecked()) { ui->matrixAll_radioButton->setChecked(false); ui->matrixRow_radioButton->setChecked(false); ui->matrixColumn_radioButton->setChecked(false); ui->matrixChange_radioButton->setChecked(false); m_matrixID = MATRIX_SINGLE; } else { m_matrixID = -1; } } else if (sender() == ui->matrixRow_radioButton) // 整行 { if (ui->matrixRow_radioButton->isChecked()) { ui->matrixSingle_radioButton->setChecked(false); ui->matrixAll_radioButton->setChecked(false); ui->matrixColumn_radioButton->setChecked(false); ui->matrixChange_radioButton->setChecked(false); m_matrixID = MATRIX_ROW; } else { m_matrixID = -1; } } else if (sender() == ui->matrixColumn_radioButton) // 整列 { if (ui->matrixColumn_radioButton->isChecked()) { ui->matrixSingle_radioButton->setChecked(false); ui->matrixRow_radioButton->setChecked(false); ui->matrixAll_radioButton->setChecked(false); ui->matrixChange_radioButton->setChecked(false); m_matrixID = MATRIX_CLUMN; } else { m_matrixID = -1; } } else if (sender() == ui->matrixChange_radioButton) // 取反 { if (ui->matrixChange_radioButton->isChecked()) { ui->matrixSingle_radioButton->setChecked(false); ui->matrixRow_radioButton->setChecked(false); ui->matrixAll_radioButton->setChecked(false); ui->matrixColumn_radioButton->setChecked(false); m_matrixID = MATRIX_CHANGE; } else { m_matrixID = -1; } } ui->widget_2->setMouseOpstatus(MatrixImageWidget::MOS_SELECT_POS); }
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值