I have created an simple app which has string input(edit text) and displays the string on click of the button using text view. I have used vertical scroll view, The problem is right side characters hidden. Here is the code I used
public class MainActivity extends Activity {
TextView text;
EditText txt;
Button btn;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text = (TextView)findViewById(R.id.dis);
txt = (EditText)findViewById(R.id.mesg);
btn = (Button)findViewById(R.id.button);
}
public void Display(View v) {
String msg=txt.getText().toString();
text.setText(msg);
//text.setText("yes");
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff000000"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:baselineAligned="true"
android:gravity="bottom" >
<TableRow android:padding="10dp" >
<EditText
android:id="#+id/mesg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:ems="10"
android:hint="Message"
android:text="" >
</EditText>
</TableRow>
<TableRow android:padding="10dp" >
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Display"
android:text="Dispaly" />
</TableRow>
<TableRow android:padding="10dp" >
<TextView
android:id="#+id/dis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="#ffffff" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
As you see the 's' in says is hidden and also sometimes it happens with text view
Try this..
Add padding like android:padding="5dp" to EditText
<EditText
android:id="#+id/mesg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="5dp"
android:ems="10"
android:hint="Message"
android:text="" >
</EditText>
Remove the android:ems directive from your EditText.
Related
Whenever I click the sign in button in my app, it just crashes and shows an error. Here is my activity_sign_in.xml and my SignIn.java.
activity_sign_in.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#mipmap/background1"
tools:context=".SignIn">
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/editPhone"
android:hint="Phone Number"
android:textColorHint="#android:color/white"
android:text="0988112456"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="phone"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="11"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis="true"
/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id="#+id/editPassword"
android:hint="Password"
android:textColorHint="#android:color/white"
android:text="IMF"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="34sp"
android:inputType="textPassword"
app:met_baseColor="#android:color/white"
app:met_floatingLabel="highlight"
app:met_maxCharacters="11"
app:met_primaryColor="#android:color/white"
app:met_singleLineEllipsis="true"
/>
<LinearLayout
android:orientation="horizontal"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/ckbRemember"
style="#style/Material.Drawable.CheckBox"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Remember Me"
android:gravity="center_vertical"
android:textColor="#android:color/white"
app:cbd_tickColor="#color/colorPrimaryDark"
app:cbd_strokeColor="#android:color/white"
/>
<TextView
android:id="#+id/txtForgotPwd"
android:textColor="#android:color/white"
android:text="#string/forgot_pwd"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<info.hoang8f.widget.FButton
android:id="#+id/btnSignIn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:text="#string/Button2"
android:textColor="#android:color/white"
app:cornerRadius="4dp"
app:fButtonColor="#00A9D440"
app:shadowColor="#00000000"
app:shadowEnabled="true"
app:shadowHeight="5dp" />
</RelativeLayout>
SignIn.java
public class SignIn extends AppCompatActivity {
EditText editPhone,editPassword;
Button btnSignIn;
CheckBox ckbRemember;
TextView txtForgotPwd;
FirebaseDatabase database;
DatabaseReference table_user;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
editPassword = (MaterialEditText)findViewById(R.id.editPassword);
editPhone = (MaterialEditText)findViewById(R.id.editPhone);
btnSignIn = (Button)findViewById(R.id.btnSignIn1);
ckbRemember = (CheckBox)findViewById(R.id.ckbRemember);
txtForgotPwd = (TextView) findViewById(R.id.txtForgotPwd);
"Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to com.rey.material.widget.TextView"
Check your imports in SignIn.java. You are probably importing com.rey.material.widget.TextView instead of android.widget.TextView.
If you want to use the com.rey TextView instead of the normal one you have to write
<com.rey.material.widget.TextView
android:id="#+id/txtForgotPwd"
android:textColor="#android:color/white"
...
in your xml.
I'm making a football league app, and i need to show the classification.
I'm trying to show a header that indicates what represents each field and a listview with the teams below.
I'm using a SimpleCursorAdapter to fill the list, but if the values have a different number of digits the list is misaligned. ¿How can i align it or at least add a 0 before the one-digit numbers with the adapter?
The soure code of the fragment and the xml:
ClassificacioFragment.java:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String[] from = { EquipsContract.EquipEntry.COLUMN_NAME_NOM,
EquipsContract.EquipEntry.COLUMN_NAME_VICTORIES, EquipsContract.EquipEntry.COLUMN_NAME_DERROTES,
EquipsContract.EquipEntry.COLUMN_NAME_EMPATS, EquipsContract.EquipEntry.COLUMN_NAME_PUNTS};
int[] to = {R.id.item_nom, R.id.item_victories, R.id.item_derrotes, R.id.item_empats, R.id.item_punts};
View rootview = inflater.inflate(R.layout.fragment_classificacio, container, false);
ListView listView = (ListView) rootview.findViewById(R.id.classificacio);
listView.invalidateViews();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(rootview.getContext(), R.layout.equip_row,
DBHandler.getDbInstance(getContext()).cursorClassificacio(), from, to);
listView.setAdapter(adapter);
String size = Integer.toString(DBHandler.getDbInstance(getContext()).getAllEquips().size());
Toast toast = Toast.makeText(getContext(), size, Toast.LENGTH_LONG);
toast.show();
return rootview;
}
fragment XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="idi.francesc.footballleague.ClassificacioFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/header_classificacio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_equip"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginStart="28dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_victories"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_d"
android:layout_marginEnd="30dp"
/>
<TextView
android:id="#+id/header_d"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_derrotes"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_e"
android:layout_marginEnd="27dp"
/>
<TextView
android:id="#+id/header_e"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_empats"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/header_p"
android:layout_marginEnd="38dp"
/>
<TextView
android:id="#+id/header_p"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="#string/header_punts"
android:textSize="18sp"
android:layout_marginEnd="12dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<ListView
android:id="#+id/classificacio"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/header_classificacio">
</ListView>
</RelativeLayout>
</FrameLayout>
Listview Row:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/item_nom"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:textSize="20sp"
android:padding="2dp"
android:layout_marginStart="10dp"
android:text="F.C. Barcelona"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_victories"
android:padding="2dp"
android:textSize="15sp"
android:text="10"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_derrotes"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_derrotes"
android:padding="2dp"
android:textSize="15sp"
android:text="20"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_empats"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeight"
android:id="#+id/item_empats"
android:padding="2dp"
android:textSize="15sp"
android:text="30"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/item_punts"
android:layout_marginEnd="25dp"/>
<TextView
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="wrap_content"
android:id="#+id/item_punts"
android:padding="6dp"
android:textSize="18sp"
android:text="40"
android:gravity="center_vertical"
android:layout_marginEnd="2dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
And this is the result:
thanks.
You can simplify your ListView Row to use LinearLayout with weight parameters. It's more efficient and prevents issues with TextView's floating width.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="9">
<TextView
android:id="#+id/item_nom"
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:textSize="20sp"
android:padding="2dp"
android:layout_marginStart="10dp"
android:layout_weight="4"
android:text="F.C. Barcelona"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_victories"
android:textSize="15sp"
android:text="10"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_derrotes"
android:textSize="15sp"
android:text="20"
android:gravity="center"/>
<TextView
android:layout_width="0dp"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_weight="1"
android:id="#+id/item_empats"
android:textSize="15sp"
android:text="30"
android:gravity="center"/>
<TextView
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="0dp"
android:layout_weight="2"
android:id="#+id/item_punts"
android:textSize="18sp"
android:text="40"
android:gravity="center"/>
</LinearLayout>
At first all of your text in the TextView must be center aligned.
android:gravity="center"
Then, pogramatically you should find the largest TextView and set the width of each other TextView in that row.
Or you use TableLayout ;)
Create a function for appending 0 with numbers less than 10.
public String appendZero(int input) {
if (input >= 10) {
return String.valueOf(input);
} else {
return "0" + String.valueOf(input);
}
}
While setting the text, call like this :
item_victories.setText(appendZero(victory_count.get(position)));
Hope this one will works for you.
I am attempting to have have a edittext box appear when a certain radiobutton in a group is checked. I am getting the error with setVisibility, and when running the error that it says is int cannot be dereferenced.
JAVA
public class MainActivity extends AppCompatActivity {
//Declared some variables here. One for each field in the form
ShareActionProvider mShareActionProvider;
String feedbackType;
String feedback;
String email;
String fName;
String lName;
String fAnswer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RadioGroup radiochoice=(RadioGroup) findViewById(R.id.radiochoice);
radiochoice.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.RejectRadio) {
R.id.RejectResponse.setVisibility(View.VISIBLE);}
else if (checkedId == R.id.AcceptRadio) {
R.id.RejectResponse.setVisibility(View.INVISIBLE);}
}
});
}
XML (This works okay just for reference/review)
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:id="#+id/TextViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/feedbacktitle"
android:textSize="10pt">
</TextView>
<!--First Name-->
<EditText
android:id="#+id/EditTextFirstName"
android:layout_height="wrap_content"
android:hint="#string/feedbackfirst"
android:inputType="textPersonName"
android:layout_width="fill_parent"
android:layout_below="#+id/TextViewTitle">
</EditText>
<!--Last Name-->
<EditText
android:id="#+id/EditTextLastName"
android:layout_height="wrap_content"
android:hint="#string/feedbacklast"
android:inputType="textPersonName"
android:layout_width="fill_parent"
android:layout_below="#id/EditTextFirstName">
</EditText>
<!-- Email -->
<EditText
android:id="#+id/EditTextEmail"
android:layout_height="wrap_content"
android:hint="#string/feedbackemail"
android:inputType="textEmailAddress"
android:layout_width="fill_parent"
android:layout_below="#id/EditTextLastName">
</EditText>
<Spinner
android:id="#+id/SpinnerFeedbackType"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:entries="#array/Types_of_Errors"
android:layout_below="#+id/EditTextEmail">
</Spinner>
<EditText
android:id="#+id/EditTextFeedbackBody"
android:layout_height="wrap_content"
android:hint="#string/feedbackbody"
android:inputType="textMultiLine"
android:lines="5"
android:layout_width="fill_parent"
android:layout_below="#+id/SpinnerFeedbackType">
</EditText>
<RadioGroup
android:id="#+id/radiochoice"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/EditTextFeedbackBody"
android:orientation="horizontal">
<RadioButton
android:id="#+id/AcceptRadio"
android:layout_width="wrap_content"
android:layout_marginStart="50dp"
android:layout_height="wrap_content"
android:text="#string/acceptbutton" />
<RadioButton
android:id="#+id/RejectRadio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rejectbutton"
android:layout_marginStart="115dp" />
</RadioGroup>
<EditText
android:id="#+id/RejectResponse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="#string/rejectreason"
android:layout_marginTop="410dp"
android:layout_alignParentEnd="true"
android:layout_marginRight="20dp"
android:inputType="text"/>
<Button
android:id="#+id/ButtonSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/sendform"
android:layout_centerHorizontal="true"
android:layout_marginTop="590dp"
android:onClick="submit"/>
</RelativeLayout>
You have to do this:
//Reference rejectResponse
EditText rejectResponse = (EditText) findViewById(R.id.RejectResponse);
//Change visibility
rejectResponse.setVisibility(View.INVISIBLE);
This might be useful: Android View
I have added an imageswitcher to my register fragment, when the user select his/her gender the image changes but the image shown is too big and I cant scale it. I am using a scrollview and it is not good that the Imageswitcher is bigger than screen. I tried using smaller images but the result is same. Here is my XML:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/registerbackground"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#+id/kayit_kayit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/register"
android:textColor="#FFFFFFFF"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintAd"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_soyad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintSoyad"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<EditText
android:id="#+id/kayit_email"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:hint="#string/hintEmail"
android:inputType="textEmailAddress"
android:textColor="#FFFFFFFF" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/kayitKiz"
android:textColor="#FFFFFFFF" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/kayitErkek"
android:textColor="#FFFFFFFF" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageSwitcher
android:id="#+id/cinsiyetSwitcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ImageSwitcher>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<EditText
android:id="#+id/kayit_kelime1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="50dp"
android:hint="#string/hintKelimeler1"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="#+id/kayit_kelime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/hintKelimeler2"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
<EditText
android:id="#+id/kayit_kelime3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="50dp"
android:hint="#string/hintKelimeler3"
android:inputType="textNoSuggestions"
android:textColor="#FFFFFFFF"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
and the code for the imageswitcher:
....
cinsiyetSwitcher = (ImageSwitcher) rootView.findViewById(R.id.cinsiyetSwitcher);
cinsiyetSwitcher.setFactory(new ViewFactory() {
#Override
public View makeView() {
ImageView imageView = new ImageView(getActivity());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
return imageView;
}
});
kizRadio = (RadioButton) rootView.findViewById(R.id.radio0);
erkekRadio = (RadioButton) rootView.findViewById(R.id.radio1);
kizRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir1(v);
}
});
erkekRadio.setOnClickListener( new View.OnClickListener() {
public void onClick(View v)
{
degistir2(v);
}
});
....
...
public void degistir1(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
cinsiyetSwitcher.setInAnimation(in);
cinsiyetSwitcher.setOutAnimation(out);
cinsiyetSwitcher.setImageResource(R.drawable.kari);
}
public void degistir2(View view)
{
Animation in = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_out_right);
Animation out = AnimationUtils.loadAnimation(getActivity(),
android.R.anim.slide_in_left);
cinsiyetSwitcher.setInAnimation(out);
cinsiyetSwitcher.setOutAnimation(in);
cinsiyetSwitcher.setImageResource(R.drawable.adam);
}
I have an activity that displays various radiobuttons. The radiobuttons are grouped in radiogroups. I want some of the radiobutton to disappear when a certain radiobutton is checked. eg when the incident button is checked the fall, trip and illness radiobutton disappear. how can i achieve this?
I have the foolowing code but need to somehow attach a listener to the incident button.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reportsomethinglayout);
resolution = (EditText)findViewById(R.id.editTextresolution);
// resolution.setInputType(InputType.TYPE_NULL);
// showSoftKeyboard(resolution);
accident = (RadioButton)findViewById(R.id.radioButtonaccident);
incident = (RadioButton)findViewById(R.id.radioButtonincident);
concern = (RadioButton)findViewById(R.id.radioButtonconcern);
fall = (RadioButton)findViewById(R.id.radioButtonfall);
trip = (RadioButton)findViewById(R.id.radioButtonTrip);
illness = (RadioButton)findViewById(R.id.radioButtonillness);
}
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radioButtonaccident:
if (checked)
Log.e(TAG, "accident radiobutton checked");
break;
case R.id.radioButtonincident:
if (checked)
Log.e(TAG, "incident radiobutton checked");
fall.setVisibility(View.GONE);
trip.setVisibility(View.GONE);
illness.setVisibility(View.GONE);
break;
}
}
.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/carefreebgscaledalphajpg" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearlayoutasscrollneedsonenamedchild" >
<TextView
android:id="#+id/reportsomethingtitletextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carer Reporting"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_gravity="center" />
<TextView
android:id="#+id/textViewcategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Category" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioButtonaccident"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Accident" />
<RadioButton
android:id="#+id/radioButtonincident"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Incident" />
<RadioButton
android:id="#+id/radioButtonconcern"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Concern" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/textViewspacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="" />
<TextView
android:id="#+id/textViewtype"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Type" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioButtonfall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fall" />
<RadioButton
android:id="#+id/radioButtonTrip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Trip" />
<RadioButton
android:id="#+id/radioButtonillness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Illness" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/textViewspacer2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="" />
<TextView
android:id="#+id/textViewaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Action" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioButtonCallDoctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Call Doctor" />
<RadioButton
android:id="#+id/radioButtoncalledkin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Called next of kin" />
</RadioGroup>
</LinearLayout>
<TextView
android:id="#+id/textViewspacer3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="" />
<TextView
android:id="#+id/textViewresolution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Resolution" />
<EditText
android:id="#+id/editTextresolution"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="1"
android:lines="8"
android:inputType="textMultiLine"
>
<requestFocus />
</EditText>
<Button
android:id="#+id/buttonsubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Submit" />
</LinearLayout>
</ScrollView>
</LinearLayout>
try like this:-
RadioGroup group = (RadioGroup) findViewById(R.id.radioGroup1);
group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
// TODO Auto-generated method stub
if(radiobutton1.isChecked()) {
fall.setVisibility(View.GONE);
trip.setVisibility(View.GONE);
illness.setVisibility(View.GONE);
} else if(radiobutton2.isChecked()) {
}
}
});
You can set a listener on a RadioGroup with setOnCheckedChangeListener. The onCheckedChanged callback receives the ID of the newly checked button in the checkedId parameter.
In your case, just add an ID to your radio group (in order to retrieve it from your code)
<RadioGroup
android:id="#+id/category_group"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
And use the following code:
RadioGroup categoryGroup = (RadioGroup) findViewById(R.id.category_group);
categoryGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId) {
case R.id.radioButtonincident:
// 'Incident' checked
fall.setVisibility(View.GONE);
trip.setVisibility(View.GONE);
illness.setVisibility(View.GONE);
break;
case R.id.radioButtonaccident:
// 'Accident' checked
break;
case R.id.radioButtonconcern:
// 'Concern' checked
break;
}
}
});