English 中文(简体)
选择一种观点
原标题:Bring a view on selecting one view
  • 时间:2010-11-29 08:29:47
  •  标签:
  • android

hii i want to create a ui in which as i select a radio button there should come a textview. when that button is not selected text view should not be visible. and as button got selected it should be visible..can i implement this??

最佳回答

在听众中,如果选用无线电台,请查看:

 findViewById(R.id.yourtextview).setVisibility(View.INVISIBLE);

以及

 findViewById(R.id.yourtextview).setVisibility(View.VISIBLE);

You can choose between INVISIBLE 以及 GONE.

Tutorial to manage radio buttons

问题回答

页: 1

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class MainActivity extends Activity {

    private RadioButton radioButton1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



        radioButton1 = (RadioButton) findViewById(R.id.RadioButton1);


        RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
        radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if(radioButton1.isChecked()) {
                    findViewById(R.id.textView).setVisibility(View.VISIBLE);
                } else {
                    findViewById(R.id.textView).setVisibility(View.GONE);
                }
            }
        });
    }
}

And here is the xml layout: Main.xml

希望能帮助你们。

public class _alefon_radio extends Activity implements OnCheckedChangeListener {
 /** Called when the activity is first created. */
 private TextView tx;
 private RadioGroup rg;

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  tx = (TextView) findViewById(R.id.tvv);
  rg = (RadioGroup) findViewById(R.id.rgroup);
  rg.setOnCheckedChangeListener(this);
 }

 @Override
 public void onCheckedChanged(RadioGroup group, int checkedId) {

  switch (checkedId) {
  // for R.id.option1
  case R.id.option1:
   tx.setText("option one is checked");
   //tx.setVisibility(0); //visible 
   break;
  default:
   tx.setText("");
   //tx.setVisibility(4); //invisible

  }

 }
}

排外:

<?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"
    >
<TextView  
 android:id="@+id/tvv"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text=""
    />
    <RadioGroup
    android:id="@+id/rgroup"
  android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical">
   <RadioButton
    android:id="@+id/option1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Option 1" />
   <RadioButton
    android:id="@+id/option2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Option 2" />
   <RadioButton
    android:id="@+id/option3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Option 3" />
 </RadioGroup>
</LinearLayout>

我使用了it本案文,而不是制造反弹/无形的,但如果你愿意使用这种方式,我也包含对等控制(合并)。

我希望这是你所期待的。

好的桶





相关问题
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 ...

热门标签