I don't speak english very well, so please try to understand me.
iìm trying to develop a little app for android in eclipse. I've create 2 layout where, in first there are a button and in a second there is only the text "helloword". I want that the button to send me at the "helloworld" layout
I followed a tutorial but it's not correct.
Someone can help me posting th code to implement??
Excuse my English still
and thanks for any help
You need to create two different Activities, with separate layouts. You set their layouts using setContentView inside onCreate. Don't forget to include your activities in the manifest (eclipse generated one for you. follow how it was done in the first activity and you should be fine. no need to add the filters and such, just the .Activity)
then in your first activity's button, do this:
my_button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(this, MySecondActivity.class);
startActivty(i);
}
});
If you want to use just 1 activity then use the following code,
my_button.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
FirstActivity.this.setContentView(R.layout.second_layout);
}
});
Its not so hard just do this:
#Override
public void onClick(View args0) {
setContentView(R.layout.aardelayout);
}
just a simple Search on google and you find your answer .
see this tutorials ( two are in frensh if you are prefering frensh tutorials ) :
tuto1
tuto2
tuto3
Related
I am fairly new to programming, I was writing an application code in Android Studio but had a problem
It turns out that when I put this line in my code (In image)
it does not detect it and an error occurs both with "onClick" and with "(v)" I reached this point and I don't know how to solve it
Attached images:
[1]: https://i.stack.imgur.com/huZLu.png Error Code
[2]: https://i.stack.imgur.com/hCJYJ.png All Code
I would really appreciate the answer
This problem is eating my head!
Thank you
it's not a big problem, you can write like this, it will solve your issue
mOpicon2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
I have a problem with creating more than one activity in an Android project. The problem occurs only when i'm debugging. It's not a runtime error. I don't have any clue why i still keep getting this error. I already did a lot of research but now I'm a bit desperate because solutions on the web didn't solve the problem.
The error more detailed:
Source not found
Source not found for the file Activity.class error
The source attachment does not contain the source for the file Activity.class
[Button] Change Attached Source
When i click on that button i see the path to the android.jar file:
C:/Program Files/android/platforms/android-19/android.jar
[SOLVED]
This is an good tutorial how to solve this problem.
https://www.youtube.com/watch?v=IdIZ7r2d4J4
Looking at your code i notice a few anomalies.Please use
protected void onCreate()
and not public void onCreate()
I'm not familiar with Java for Android but it looks like your code is trying to use the same UI space for two fullscreen windows.
May be it is something with casing?
Can you be more specific about your problem.
1) Is it a compile error or runtime?
2) What message you got in either case?
Original doc: http://developer.android.com/training/basics/firstapp/starting-activity.html
Simple code for starting second activity by button with id = button
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
}
});
}
Sorry for my newbie Question, i just cannot find the answer from google and stackoverflow.. i just start learning for android, wish can build a good base for android knowledge. I wondering which i should use in the following if i create toast.maketext in fragment. getActivity() or getAcitivity().getApplicationContext()?
i did try both, it works well..
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getActivity(), "hello",Toast.LENGTH_LONG).show();
Toast.makeText(getActivity().getApplicationContext(),"Hello",Toast.LENGTH_LONG).show();
}
});
For user interface related calls use the Activity context.
See this explanation by Reto Meier:
https://stackoverflow.com/a/987503/534471
I apologize for this, and I am sure it's a very rookie question... but I am still trying to grasp java and how everything works (I'm surprised I made it this far.)
I have a TextView inside of a ScrollView and I am trying to get it to focus on the bottom entry each time a new entry is added.
I have this in the code:
getScrollView().post (new Runnable() {
#Override
public void run() {
getScrollView().fullScroll(ScrollView.FOCUS_DOWN);
}
});
that is inside the
public void onClick(View src) {
switch(src.getId()){
case R.id.buttonOk:
(So that when I click ok, it will focus to the bottom.)
now.. I am getting this error: The method getScrollView() is undefined for the type
do i need to call out the name of the scroll view within that first set of code, android:id="#+id/scrollView1"
Again, I am sorry I am so confused on this. I am obviously not getting something right here. Any help is greatly appreciated.
Thanks
you can used this.
scrollview=((ScrollView) findViewById(R.id.scrollview));
scrollview.post(new Runnable() {
#Override
public void run() {
scrollview.fullScroll(ScrollView.FOCUS_DOWN);
}
});
A couple things:
To get access to the view from code, you use (ScrollView)findViewById(R.id.scrollView1) -- getScrollView() doesn't exist, though you can write it using the command I described.
Based on what it sounds like you're trying to do, you might want to look into ListView instead (rather than appending lines to a TextView).
I already asked this question, but got answers that don't work and it counted as "Answered". Maybe someone knows how to design button in Eclipse for an Android app, so it takes you to a website ?Let's say this website.Thanks a lot.
Say u wanna go to google.com
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("https://www.google.co.in/"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
}
}
}
Make sure u add uses internet permission to the manifest!
you can refer the following to get an idea ,
see this vogella from there, you can get idea how to create android app which has a Button
http://www.vogella.de/articles/Android/article.html
and then create WebView in xml and map it in java, as
http://developer.android.com/resources/tutorials/views/hello-webview.html
and For mor info refer android people.com
http://www.androidpeople.com/
http://developer.android.com/resources/samples/index.html
and also read my blog to know about android basics
http://sankarganesh-info-exchange.blogspot.com/p/corridor-your-foremost-footstep-in.html
You would need to set up an OnClickListener and tie it to your button. In the Listener's onClick method, you would load the specified URL into the WebView, which, based on your comments, it sounds like you've got that part figured out.