int radioId = radioGroup2.getCheckedRadioButtonId();
radioButton2 = findViewById(radioId);
textView1.setText(radioButton2.getText() + " > ");
I want to display the label of checked radio button in the next activity like this -----> Android Developers > Docs > Guiders
Please help me.
Next, how can I display the label of checked radio button
(first activity) in the third activity ?
There is several ways that's depend on your need:
Using Intent Data
You can put that text as extra into your intent that starting next activity:
Intent i = new Intent(firstActivity.this, nextActivity.class);
i.putExtra("CheckedRadioText", radioButton2.getText());
startActivity(i);
And get extra at next activity's onCreate method like below:
Intent i = getIntent();
String text = i.getStringExtra("CheckedRadioText");
myTextView.setText(text);
You can set radio button's text to a static string and access it from next activity easily (personally, not recommended).
If this radio button is something like setting selection that you need to save this. Then you can save that text to a sharedPreference. There are several tutorials available for this approach.
Related
I have a listview (for player names entered in the edittext on my loginpage). My second activity page (the actual game refers to those player names (projects the first of the list top of the screen as can be seen here: https://gyazo.com/7d8f003cc28f02343715edc66af1d819).
In order to do so, I created the following intent on the loginpage:
public void openActivity2() {
Intent intent = new Intent(this, Gamescreen.class);
String s= list.get(0);
intent.putExtra("Name1", s);
startActivity(intent);
}}
In the game screen I refer to this as such:
Intent iin= getIntent();
Bundle b = iin.getExtras();
if(b!=null)
{
String j =b.getString("Name1");
playerturn.setText(j);
}
Basically what I want is that when I press the button (next player) on the gamescreen that it moves from the first player name on the list to the second. As such as you keep clicking the next player button -> you move down the list.
I will need to make an onclicklistener for the click of the button, but how do I make the rest possible, with the current way I have approached it? Help much appreciated!
I have two activities, one is a clicker game (where you click a button and the textView displays an int (increasing per click). The other activity is where I display that int. I've tried many times of different ways of how to pass this data to the next activity, however nothing seemed to work. I assume that this could be because this int does not stay the same, and is constantly changing. Could anyone suggest what to do?
Clicker:
Intent getNumber = new Intent(this, Shop.class);
getNumber.putExtra("passedMoney", clicks);
startActivity(getNumber);
Stats:
Intent getNumber = getIntent();
int clicks = getNumber.getIntExtra("passedMoney", 0);
clicks is the int, which is 0.
Thanks in advance :)
Send data on click
startActivity(new Intent(vContext, OtherActivity.class).getIntExtra("number", itemData));
How to get data
int pos = getIntent().getIntExtra("number", 0);
I have an Activity from which I get some input that I must use afterwards. I get an Integer number from a NumberPicker and an ArrayList<String> from a multiple choice AlertDialog. In that Activity I also have a button that starts the "game". When the button is clicked I want to open a new Activity so I can use the Integer number and the ArrayList but I will lose them if I go to a new Activity. So my guess is I should create a new Layout from the current Activity and handle the input there. I need some TextViews and a counter that can be dynamically changed on button click. For example the first TextView will be the first element of that ArrayList. On button clicks the counter must add 1 (counter += 1). When the counter equals the Integer number from the NumberPicker (user input) the TextView must change from ArrayList(first element) to ArrayList(second element). I don't need help on the logic. This was just to clarify things. I need to know how to do that with a layout dynamically. I need some guidance how can I do that or is that the way to go (layout not Activity). Tutorial links/examples/advice will help me a lot.
When the button is clicked I want to open a new Activity so I can use
the Integer number and the ArrayList but I will lose them if I go to a
new Activity.
Look into the putStringArrayListExtra() method in the Intent class. This will allow you to pass your ArrayList to the new Activity:
List<String> stringArrayList = new ArrayList<>();
int intValue = 5;
Intent i = new Intent(ActivityOne.this, ActivityTwo.class);
i.putExtra("int_key", intValue);
i.putStringArrayListExtra("string_key", stringArrayList);
startActivity(i);
I have a DetailsActivity which has a TextView and TimeEditText for Date. User can add a date in that. There is a Button called Add Detail
I want that when a user enters a date like d-m-yy (future) then below this TimeEditText element, the activity should show a no. of WeekEditText as
Week1: WeekEditText1 (To add details for 1st week)
Week2: WeekEditText2 (To add details for 2nd week) and so on.
The total no. of week is (AddedDate - CurrentDate)/7
One of way of doing is calling another new activity on clicking Add Detail button and then showing all EditTexts on next activity while passsing AddedDate etc through Intent.
But is it possible to show EditText on same page below TimeEditText after user enters a date?
Have a Button that when clicked adds the number of EditTexts you need
public void onClick(View v)
{
// do whatever else you need here
int numWeeks =(AddedDate - CurrentDate)/7;
for (i=1; i<=numWeeks;i++)
{
EditText et = new EditText(YourActivity.this);
// add whatever here
}
}
You can add whatever kind of Layout you want before creating the EditText then add each one to that Layout. Something like that ought to work for you
You can dynamically inflate a layout or layout element such as and Edit Text.
For Example,
if(TimeEditText.getText != null)
EditText et = new EditText();
I have a TabLayoutObjectActivity that shows 2 tabs with a different activity(TabActivity1 & TabActivity2).
I have another activity called ObjectActivity. It contains an array and if it is clicked I want the app to change to the TabLayoutObjectActivity (which shows TabActivity1 first) and sends a string from an array that clicked to TabActivity1.
I have tried some code but the app always wants to force close after I click one of the array list.
Intent i = null;
i = new Intent(this, TabLayoutObjekActivity.class);
Intent ii = null;
ii = new Intent(this, TabActivity1.class);
ii.putExtra("name", String.valueOf(menuArray[position].toString()));
startActivity(i);
startActivity(ii);
Please give me your opinion how to do this. Thanks :)
Refer to this. It explains how to solve your problem in detail. onclick even you can handle the issue.