today I used Android Studio 1.4 for the first time. I decided to make a app that helps you find a movie to watch. Very basic. Main page with a buttom that sends you to a random movie with tittle, poster, imdb link and a buttom that sends you to a new random movie.
I got two problems.
The Mainpage buttom that sends the user to a random activity is not working. How can i code it so it will send the user to a random activity and preferred not the same one. Can you make it choose from 1 of 100 activities?
I only get a error when I try to bind the Imdb link to a button.
Well your asking a question which requires to do some looking around. You are asking some basic question, which you should be able to do.
Here is a little code that you can use
Button yourButton = (Button) findViewById(R.id.your_buttons_id);
yourButton.setOnClickListener(new OnClickListener(){
public void onClick(View v){
startActivity(new Intent(YourCurrentActivity.this, YourNewActivity.class));
}
});
I personally feel like you need to check some tuts online. This is the basic, if you struggle on this, then you would struggle a lot more else where.
Anyway, if you see findViewById(R.id.your_buttons_id); it lets the app know which button that was clicked.
Related
I am still working on my first android app and hope you can help me once more. I use the YouTube API to get all the content from my channel and create the following list:
Now my problem is I do not know how I can tell the buttons in the middle of each thumbnail to start the according video. I have the correct video ID for each element (provided in a textview on the right during troubleshooting...) but when I try to connect this information to the button onclick method it will just use the first textview content on the screen, so it is always just opening the first video => for every single button.
public void jumpin(View view) {
TextView textViewHelper = (TextView) findViewById(R.id.videoIdTester);
String textViewHelperString = textViewHelper.getText().toString();
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, API_KEY, textViewHelperString);
startActivity(intent);
}
My basic problem is that the buttons are not filled with the video ID information like the textviews for example. The buttons are just created and I call the onclick method which needs the video id then which is not reachable from my perspective as soon as the list is created.
I think this is by far too complicated at the moment but I have no plan how to solve that. I can provide more code if you need it but I think this problem is more about button and api/array behaviour in general.
Anwered by myself, using an onitemclick listener instead of the buttons ...
I'm new to Android programming, and I have some questions about what type of layout to use. I am developing an application and have already done a basic mock-up of the interaction I want the user to have.
Following some tutorials I managed to build an app with a Bottom Navigation Bar with 3 Fragments, each one with it's own view. But my goals is that when the user clicks a button on one of these Fragments, the application opens a new View on the same Fragment.
What is the best way to achieve this goal? I have attached an image of the mock-up I made below, hope it helps to clarify the question. Thank you in advance for taking the time to help me!
Link to the mock-up app
That's sounds like you want to start a new Activity.
Considering you have your fragments in CurrentActivity and you want to start InvokingActivity
On clicking button in CurrentActivity
onClickMethod(View v){
Intent intent = new Intent(CurrentActivity.this, InvokingActivity.class)
//put some extras if you like
startActivity(intent)
}
To get arrow in top left corner you need to update AndroidMainfest by adding to InvokingActivity
android:parentActivityName="CurrentActivity"
I'm a newbie in android. I have an electrical device that is controlled by mobile app through Wifi. The mobile app turns the electrical device ON/OFF, and also sets the operation time of the electrical device. I can write an android app to control the operation of one or a specific number of electrical devices. That's, the number of electrical devices is static. But, the question is how to write an android app to control unknown number of devices. That's, I want to develop an android app that gives the user the ability to dynamically add and control new devices. As I early mentioned, I'm a newbie in android and I don't know how to do this. Should the android app dynamically add a new button or fragment? Any help or suggestion is highly appreciated.
Edit:
Here is what I tried to do. In the app's menu, I have "Add New Device" tap. When I click it, the app navigates into two or three fragments until it reaches the final fragment that stores the electrical device information (IP address, port number, etc.). Up to this point, I'm OK. What I'm trying to do now is to save/store this final fragment as a button to be shown on the main page of the app. That is, whenever I add a new device, I will end up having a new button shown on the main page of the app
The simplest way to solve this problem would be to work out how many buttons you need during your onCreate method. You can then create this many buttons, maybe as an array. A quick example could be
protected void onCreate(Bundle savedInstanceState) {
int numButtons;
//calculate the number of buttons you will need
Button buttons[numButtons];
for (int i = 0;i < numButtons;i++) {
buttons[i] = new Button("Button " + String.valueOf(i+1));
buttons[i].setOnClickListener(new View.onClickListener() {
#Override
public void onClick(View v) {
//code for when button 'i' is pressed.
}
});
}
}
I am a noob and have no one to help me so please forgive my ignorance.
1) I have three menus on main activity (three buttons like read, about and info). I used intent for one of the buttons. But how do I redirect the other two buttons to specific activities (view only)
public void onClick(View view) {
Intent i = new Intent(this, Main2Activity.class);
startActivity(i);
}
2) What widget should I use to display a page of article within an activity? I have used plain text but unable to format it.
Thanks for the kind help.
You need to implement an onclick listener on each of the buttons.
An example of how to implement it is available here.
It depends on what format the article is. If it is already in HTML format. You may use a WebView widget.
FYI: You can format a normal TextView, but that's probably a little more advanced and better left alone for now.
You should have no problem in using same intent to redirect.
Try to host that article online, using css and html and then just link that webpage by using web view in your activity.
I have a button on an app. Upon clicking this button a new page should appear. The new page will have a list of videos pulled from somewhere online. My problem now:
1. I have the xml page I want to show, and the java class linked to it. I know how to make a button, set an on click listener and make the onClick() method. What do I put into that onClick() method?
2. Help me become more articulate in how I describe Android processes, give me material to read, links to Android documentation. Every time I go into read someting I am overwhelmed; so I've decided to break it down into discrete and manageable tasks. What can I read that will help me understand Android terminology and how applications are ment to function better?
Thank you,
Dave
put in your onClick() method this code:
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);
Don't forget to add your new activity in the AndroidManifest.xml:
<activity android:label="#string/app_name" android:name="NextActivity"/>