English 中文(简体)
FInding ID ofecked Radio Button, • 如何脱胎
原标题:FInding ID of checked Radio Button, How to strip string form ID
  • 时间:2012-04-14 22:43:59
  •  标签:
  • android

在我的申请中,用户选择了一个无线电台,表明他想要做这个选择的体育比赛的参与者有多少。 之后,该数字被送往另一活动,以展示。 如果可能的话,如何利用无线电台的id子,并脱掉“无线电”部分,只剩下4-10号 in子?

package teamBuilder;

import com.jonahwitcig.team.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;


public class CorrectedActivity extends Activity {
    /** Called when the activity is first created. */

    TextView player1, team1;
    Button next;
    RadioGroup RBGroup;
    RadioButton RB4, RB5, RB6, RB7, RB8, RB9, RB10;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.players);

        next = (Button) findViewById(R.id.next);
        //the name of a textView i will be displaying a number in
        team1 = (TextView) findViewById(R.id.team1);
        RB4 = (RadioButton) findViewById(R.id.radio4);
        RB5 = (RadioButton) findViewById(R.id.radio5);
        RB6 = (RadioButton) findViewById(R.id.radio6);
        RB7 = (RadioButton) findViewById(R.id.radio7);
        RB8 = (RadioButton) findViewById(R.id.radio8);
        RB9 = (RadioButton) findViewById(R.id.radio9);
        RB10 = (RadioButton) findViewById(R.id.radio10);
        //names of my radio buttons
        RBGroup = (RadioGroup) findViewById(R.id.RBGroup);



        RBGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            public void onCheckedChanged(RadioGroup RBGroup, int checkedId) {

                team1.setText(checkedId);
            }
        });
问题回答

虽然这不是建议(相反的眼光如果在大批中进行,则相当缓慢,但如果很少这样做,则是无法解释的),但这里是正确的解决办法。 (考虑到你需要列入自己的错误核对/处理错误识别特征):

String resName = getResources().getResourceEntryName(checkedId);
String number = resName.substring(5);
int num = Integer.parseInt(number);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签