Basic question but i have checked a number of places and can only find information on pop up messages like toast etc.
How would I be able to link buttonA (stored in fragment xml file) so that it will view activitypage.xml?
Thanks!
One thing you can do make a new Activity for each "Screen". Let's make an example, MyNewActivity. The rest is pretty simple. In your button XML add this line:
android:onClick = "nextActivity"
Then in the Fragment that has contains buttonA, do something like this:
public void nextActivity (View v)
{
Intent intent = new Intent (getActivity(), MyNewActivity.class); //using getActivity since this is from a fragment
getActivity().startActivity (intent);
}
make sure that in MyNewActivity you put this line in onCreate
setContentView(R.layout.activitypage);
In your Activity which inflates your button implement a method to open the desired second Activity when the button is clicked. Either button.setOnClickListener() of a method declared in the xml for the button under the android:onClick="buttonClick" attribute.
Related
I am trying to make a application that will allow people to tag more people. I want to make such that when a person clicks / taps in the name of another person in the TextView, it should go to the person's profile in the application (but not in the web). How can I make it?
Any insight of how to do would be respected!
A short code of how to do would be much respected!
TextView Content Example: I am here in the city with Manoj and he is enjoying this place.
I want to make this such that when a person clicks Manoj it should be gone to the next fragment or next activity. And the data should is to sent to the server, so it is something We cant just use only onClick Listener for the text, as the text is determined and the link is created by public user not me?
The image would help you understand!
First in your java file find your TextView by xml id
TextView tv = (TextView)findViewById(R.Id.textView);
then, you have to set click listner on the textView
tv.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// here you can use intent to naviaget to another activity
}
});
I am developing an android news app which has goal to show titles in one activity in listView, and by clicking on each title it must open another activity and show description, photo and also title. These are pulled from web in JSON.
For now, I have list view in first activity which has been populated with titles from JSON,using AsyncTask and SimpleAdapter, and now, I need some theory boost how to make further progress.
So, how can I select one title and by this title get other parts of JSON and show them in another activity?
Any advice?
Have an onClickListener on the items in listView. In the onClickListener get the title and start a new activity. For the new activity add the data you need to send.
Intent intent = new Intent(this, DetailActivity.class);
// add the data here
intent.putExtra("title", title);
startActivity(intent);
In DetailActivity.java
String title = getIntent().getExtras().getString("title");
make an API call with the above title
Below is a picture of what i want.
Right now. When i click on an item (see 2 in image) then the incorrect version (see 3 in image) shows up.
How can i load the second tabhost (see 3 in image) into the framelayout of the first tabhost?
Code right now (resides in 2, see picture) (that produces the incorrect layout) is this:
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Intent i = new Intent(StaticResources.FrameContainer.getContext(), AppSecondTabHost.class);
StaticResources.FrameContainer.getContext().startActivity(i);
}
});
The static variable: StaticResources.FrameContainer is set in the main activity (see 1 in image) like this:
StaticResources.FrameContainer = (View)getTabHost().getTabContentView();
Any idea how i can rewrite the onitem click event to display the correct version? The bottom right version with 2 tabhosts as seen on the picture.
EDIT
To be extra clear. I create the tabhost in pic 1. When i click on one of the tabs an activity starts and that activity displays a list (picture 2). When i THEN click on an item in this list, this item will store its id in an intent and open a second tabhost inside the first tabhost (picture 3-4). The second tabhost (picture 3) will then read the id that was set in picture 2 in the onitemclick event.
if you are using tabhost, it will automatically handle all the tab click events if you add all the tabs onto the tabhost. you do not need to change the tabview manually using an onClickListener.
below is an example from my application:
intent = new Intent().setClass(this, deployment.class);
intent.putExtra("deploy_data", deployRawData);
spec = tabHost.newTabSpec("Deployment").setIndicator("Deployment",
res.getDrawable(R.drawable.man))
.setContent(intent);
tabHost.addTab(spec);
in this way, you are essentially bundling the activity and the tabview together before adding onto the tabhost. it should help you save a lot of efforts coding the onClickListener.
TabHost tabHost=getTabHost();
TabHost.TabSpec tabSpec;
Resources res=getResources();
tabSpec=tabHost.newTabSpec("First");
tabSpec.setIndicator("FirstTabName",res.getDrawable(R.drawable.image));
Intent i1=new Intent(this,NextClass.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec.setContent(i1);
tabHost.addTab(tabSpec);
Like this, you define Intent to the tab.
TabHost tabHost=getTabHost();
TabHost.TabSpec tabSpec;
Resources res=getResources();
tabSpec=tabHost.newTabSpec("First");
tabSpec.setIndicator("FirstTabName",res.getDrawable(R.drawable.image));
Intent i1=new Intent(this,NextClass.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
tabSpec.setContent(i1);
tabHost.addTab(tabSpec);
Like this, you define Intent to the tab. So your tab will remain constant and bottom content will be that of your activity.
On selecting an item from the list, intent it to next class where you have a different layout with only two tabs.
.
My application has an intro page made up of some text and image elements in a relative layout. I would like to be able to click any part of the screen and have it go to the next activity. Is it possible to use a entire relative layout as a button? If so how would you do this?
You can add android:clickable="true" to the XML for your RelativeLayout and use a standard OnClickListener as you would for a button.
Depending on what you're trying to do (perhaps touching anywhere to dismiss a screen?), you could also look into extending onTouchEvent(MotionEvent event) in your Activity, which would pick up any touches in the entire activity that were not responded to by views.
You can grab the root view as follows and add a click listener to it:
findViewById(android.R.id.content).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//make your call to startActivity();
}
});
This should require less maintenance than retrieving a specific layout.
Add android:onClick="myFunction" in the RelativeLayout of the XML file and make the following function in the corresponding Activity file:
public void myFunction(View view)
{
...
}
I think you will have to add android:onClick="myFunction" for all the nested XML tags too which are nested inside the main RelativeLayout.
I have an android app that extends a MapActivity, so I can't extend TabActivity.
I am inflating the content of the tabs dynamically, and everything looks good.
The problem that I'm running in to is that I get a NullPointerException when trying to bind event listeners to the views that were inflated into a tab past the first tab.
Example:
myButtonInTab2 = (Button)this.findViewById(R.id.mybuttonintab2);
myButtonInTab2.setOnClickListener(new OnClickListener(){
public void(View v){
///blah blah blah
}
});
If you are "inflating the content of the tabs dynamically", you should be calling findViewById() on the result of the inflate() call, for any widgets in that tab.