I have a listView with some items. Every item has a title, picture, and description. Now I'd like to click on particular activity and open new activity, which would be detailed view for particular item. So it needs to have the title and picture from previous activity, and a new, bigger description.
Could someone tell me how to do that?
For passing images to activities see this answer
likewise you can pass the title & description
intent.putExtra("TITLE","title value");
intent.putExtra("DESCRIPTION","Description value")
Related
So, really silly question but should toolbar title change from activity to activity? I searched for it on the Material Design Guidelines but couldn't find it. As of now it just display the app’s name on the toolbar on all activities. I am wondering if it follows material design guidelines/best practices on Android to keep it or change it according to the activity being presented.
So, should it be like the same on all activities or is it advisable/recommended to change it like: Going from home screen to Chats activity it would be App_name -> Chats instead of App_name -> App_name?
If so, what is the best way to change the title according to each activity?
Should toolbar's title change according to activity?
That depends on you not Material Design. Do you want to tell users clearly that this is another part of your app? Do you want to promote brand? Does this activity need a title at all?
what is the best way to change the title according to each activity?
I'll assume this is a technical question.
You have to mind two usages:
The activity title (or label) that's advertised to the operating system. This is used in launcher icons and in Recent Apps screen. It's also the default title text shown in the app (if applicable, read further).
The title text shown in the app.
How to assign activity title
Case 1) You have title in the manifest
If you defined the activity title in the manifest like so
<activity android:label="Some title"/>
if you don't specify it it inherits the app name.
Case 2) Assign title at run time
You can set the activity title manually at run time like so
activity.setTitle("Some title");
activity.setTitle(R.string.some_title);
Note: Inside an activity it's just setTitle(...).
Show title on screen
The default title will get automatically shown in Action Bar when you
setSupportActionBar(toolbar)
or if you manage a Toolbar yourself, you can set the title manually
toolbar.setTitle(activity.getTitle());
If you change the activity title later you'll also have to repeat the call on toolbar, there's nothing automatic about the process. I'm not sure about the Action Bar case.
You can also set the Toolbar title to anything else you like
toolbar.setTitle("Some title");
toolbar.setTitle(R.string.some_title);
I have created an activity which I need to update with posts made up of a "title" and "description". Earlier a ListView was suggested as an option but I do not know how to add two pieces of text (title and description) to each individual item of the ListView through a String array.
There is a "new post" button on the feed interface that opens a new activity containing 2 TextEdit boxes for adding the title and description.
When "post" is pressed on this second activity I am trying to move the title and description into an array that updates the ListView on the first activity with a new item containing the title and description stated within the TextEdit boxes.
Any help would be greatly greatly appreciated,
Aaron.
The best possible way to this is by using a data base. Android has a built in SQLite data base. You can store in all your data into the data base and query it to get a key/value pair array, which you can pass to your listView adapter class and get the data you need into the list view.
Hope this link helps you out-
androidsolution4u.blogspot.in/2013/09/android-populate-listview-from-sqlite.html?m=1
I am making an android app. this app consist of list. by clicking each item of list a new page opens.
this list contains 50 items.I should make 50 activity and their corresponding XML file.
so, is there any way that make this process easier that don't force me to make all this 50 activity one by one?
my reputation is not enough. so I upload related picture.
http://uupload.ir/files/oh1o_1.png
http://uupload.ir/files/zam9_2.png
Not sure what you mean by creating 50 pages. You have NOT to create a new class for each item in the list, instead you will create a new instance of a class. This is what programming, and OOP (Object Oriented Programming) comes into play.. Basically what you need to do is:
Create a "main_activity" class which will contain your list
Create a "item_detail_activity" which will show the details about your clicked item
What you need to write is the logic of "passing" the correct data depending on the clicked item. When an item in the "main_activity" is clicked, you will create a new instance of "item_detail_activity", passing the correct data (through a bundle).
BTW there are a lot of tutorials out there that will help you understand better the logic of an Android application.
If you have a list of items probably means that you have a list of objects which are of the same kind with same structure.
Due to this, you will have 50 pages which show to the user the same item with different values to variables, with the same structure.
You can make the objects in your list parcelable (refer to this), then pass it with the Intent to a second Activity you create, receive it, and at last populate the screen with the item you passed.
If you have troubles or doubts feel free to ask :)
EDIT:
Imagine your listview is called ListView, and the List of items you used to fill the listview is called list in the MainActivity do this:
ListView listView = (ListView) findViewById(R.Id.ListView);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// position is the index of selected item
// Launching new Activity on selecting single List Item
Intent i = new Intent(MainActivity.this, SecondActivity.class);
// sending data to new activity
i.putExtra("item", list.get(position));
startActivity(i);
}
});
in your SecondActivity, with getParcelableExtra("item") you retreieve the item clicked. Here with the variables of this item you can populate the page.
here is the doc for intents.
In secondActivity, if something must disappear if a variable has a certain value or is null, play with visibility or fragment: create an Activity with all case shown, than work with visibility or with fragments and adjust it ;)
Change your activity to fragment activity and write code to display the details corresponding listview click. it easy to follow.
I see this layout item in a lot of apps but I don't know the name. What is the name of this layout item pictured in the images below?
Image 1
Image 2
You might want to take a look at the PopupMenu class.
Also, this is used for the overflow menu in the Action Bar, you can read more about it here.
They are menus, read official docs.
Contextual Menus are used when you need to show a list of choices, example when you long press in a item in ListView.
Trying to make a checklist type app that when you select an element from a spinner you will be prompted for additional information. For instance if you select apple it will ask you how many and give you an editable text box to select.
Should I design the page so that it uses a new intent after each item is selected and creates a new page with the prompting and previous selections in it?
Or is there a better method?
OnItemSelectedListener and AlertDialog is the way.
1.Use OnItemSelectedListener and override the ItemSelected()
2.create and show the AlertDialog with edittext inside the ItemSelected method.
If you are not taking so many inputs from user then you can create a simple AlertDialog for getting those values on every item selected from Spinner or if there are lot of inputs needed then you should call a separate activity for that.