I need to achieve a navigation menu such as this:
I don't want to use Navigation drawer since I am already using it for other purposes.
Let me explain a little bit the situation:
I have a navigation drawer that shows a listview with some options. When user clicks on an option, navigation drawer disappear and in may content view should show some buttons with the look & feel as the image above.
When a button is pressed, a new view (corresponding to button selection) should slide in from the right.
How can I achieve this? I have not found a good resource for this.
Thanks
Jaime
I have done it finally by using a ListView.
This is the code,and I can assure it is not confusing, and in fact, this is done in every android app:
public void DrawAreas() {
final ListView areaView = (ListView) _activity.findViewById(R.id.area_list);
ArrayAdapter<TdcArea> areas = new ArrayAdapter<TdcArea>(_activity.getApplicationContext(),
android.R.layout.simple_list_item_1,
_system.getAreas()) {
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);
text.setTextColor(Color.BLACK);
Drawable icon = ContextCompat.getDrawable(_activity.getApplicationContext(), R.drawable.chevron_red);
text.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null);
return view;
}
};
areaView.setAdapter(areas);
areaView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TdcArea area = (TdcArea) areaView.getItemAtPosition(position);
Intent intent = new Intent(_activity.getApplicationContext(), FormActivity.class);
intent.putExtra("AREA", area);
_activity.startActivity(intent);
}
});
Related
I am using the below material design for my android app, in my app i also include the navigation drawer on new version 23 , in this grid view each image i click this to open new activity page,.
But in my app, i will not be opened , if i clicked left side above part section only the respective activity will be opened ,
Shall i know how to change the position for the click on my grid view image correctly ,
Please help me to solve my issue ,
Please check the image for clarification !!!
Thank you in advance
You can add ClickListener inside adapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
gridView =new View(mContext);
gridView = inflater.inflate(R.layout.gridview_members, null);
Button city = (Button) gridView.findViewById(R.id.city);
city.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast here
}});
return gridView;
}
Hopefully above code will help you
As in Play Store application we can see tiles of Application arranged in a Horizontal Gridview. How have they done this?
Easy, GridView tile contains ImageView, TextView, And a Button (maybe an ImageView) which looks like a menu button seen in other applications. On clicking it we can see a context menu popping up with an option to install that Application. I was able to setup everything like they did but cannot use registerForContextMenu inside BaseAdapter. Kindly help me out of it.
EDIT:
#Override public View getView(int position, View convertView, ViewGroup parent)
{ LayoutInflater l = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = l.inflate(R.layout.flowadapter,null);
TextView t = (TextView)v.findViewById(R.id.textView10);
TextView t2 = (TextView)v.findViewById(R.id.textView7);
ImageView im = (ImageView)v.findViewById(R.id.imageButton7);
c.registerForContextMenu(im);
String s = arr.get(position);
t.setText(s);
error on c.registerForContextMenu(im);
The Play Store is using a PopupMenu that is shown when clicking the overflow icon. You can find a tutorial here.
Try this below code in your activity not in the class that extends base adapter i am using this way in my application.
yourGridView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
#Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
registerForContextMenu(yourGridView);
}
});
this will help you out. If you want to get the text in Textview t on the particular item that you clicked you can add String string = t.getText().toString();
in your on click listner.
Well, I have a horizontal LinearLayout, with items of a custom class.
What I want: Change background color of the item i've clicked (like if it's selected). If user clicks other item, the first one changes again to original color and the new one changes to "selected color"
What is my problem: This works fine when all items of the listView fit in the screen ( in this case 3 items). If there are more items, let's say 7, if user clicks item number 0, it changes color, but if user scrolls to the last item and clicks item number 6, it changes color, but item 0 doesn't change. If both items are visible, it works fine.
this is the code of my onItemClickListener.
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(it.sephiroth.android.library.widget.AdapterView<?> parent, View view, int position, long id) {
for(int i=0;i<listView.getCount();i++){
try{
getViewByPosition(i, listView).setBackgroundResource(R.drawable.skin);
listView.getChildAt(i).setBackgroundResource(R.drawable.skin);
}
catch(Exception e){
System.out.println(e.toString());
}
}
view.setBackgroundResource(R.drawable.skin_selected);
}
});
why not use the adapter for the modification?I presume you are using a custom adapter?
in You Adapter
public int selectedItem;
.
//Rest of the stuff
.
.
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
if (null == convertView) {
LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, parent, false);
}
if(selectedItem==position){
convertView.setBackgroundResource(R.drawable.skin_selected);
}else{
convertView.setBackgroundResource(R.drawable.skin);
}
return convertView;
}
and your onclick listener becomes :
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(it.sephiroth.android.library.widget.AdapterView<?> parent, View view, int position, long id) {
((NameOfYouAdpater)listView.getAdapter()).selectedItem=position;
((NameOfYouAdpater)listView.getAdapter()).notifyDataSetChanged();
}
});
And I noticed you are using a custom list view in itself.Maybe look into the implementation of the library to check for interference?
EDIT:the cause of your issue is most probably dude to view recycling.The background colour does not get updated because everytime the list item is outside your ViewPort,the view is recycled.
I'm facing some trouble with the navigation drawer adapter.
It's supposed to display items as follows: Favorito, Categorias, and small sub categories underneath categorias.
I programmed the navigation drawer adapter to use a big_layout.xml file by default, but if its position is greater than a certain value, then it uses a small_layout.xml file.
It works fine for the first few items, but the problem is when I scroll down to see the rest of the items, they use the big_layout.xml, and then when I scroll back up, the original big items change their view and use the small layout!
below is the code, and this is a screen shot of the bad results: http://i.stack.imgur.com/QWwts.jpg
#Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater laoutInflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (getItemId(position)>3)
view = laoutInflater.inflate(R.layout.drawer_list_item_small, null);
if (getItemId(position)<=3)
view = laoutInflater.inflate(R.layout.drawer_list_item, null);
}
ImageView icon = (ImageView) view.findViewById(R.id.icon);
icon.setImageResource(drawerItems.get(position).getIcon());
TextView title = (TextView) view.findViewById(R.id.title);
title.setText(drawerItems.get(position).getTitle());
return view;}
Is there anything wrong I'm doing ? , Is there something missing that might be responsible of making the view stable?
How can i fix this ?
Your issue is with recycling. When you scroll down and back up, the views using the small layout are no longer needed, and so are eligible for recycling - now, the view is not null, so the layout will not be reinitialised based on its position, but merely updated with the new content.
You can fix this by using ViewTypes in your list adapter class, overriding the following methods.
#Override
public int getItemViewType(int position) {
return (position > 3) ? 0 : 1;
}
#Override
public int getViewTypeCount() {
return 2;
}
Then, in your getView() you will not be given a view (for recycling) if it is of the wrong view type.
#Override
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
int layout = getLayoutForViewType(position);
view = LayoutInflater.from(parent.getContext()).inflate(layout, null);
}
...
return view;
}
private int getLayoutForViewType(int position) {
if (getItemViewType(position) == 0) {
return R.layout.blahblahblah;
}
return R.layout.bloobloobloo;
}
Currently, I need to access parts of the ActionBar in order to attach contextual help bubbles in appropriate locations. That seems fairly simple for Menu Items as menuItem.getActionView is available.
However, I'm not sure how to get similar access to the navigation list in the ActionBar. Instead of including items in the menu xml file, the navigation options and listeners are added like this:
getActivity().getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
getActivity().getActionBar().setListNavigationCallbacks(mNavigationListAdapter, this);
With Menu Items, the following works:
MenuItem menuItem = menu.findItem(R.id.my_nifty_menu_item);
View viewToAttachHelpBubbleTo = menuItem.getActionView();
How can I get a similar view reference to the navigation menu used in the ActionBar?
It is possible to store the view in the Adapter and then pull it from there.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// Stuff happens...
mLastParentView = parent;
}
#Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
// Stuff happens...
mLastParentView = parent;
}
public View getLastParentView() {
return mLastParentView;
}
and then after
getActivity().getActionBar().setListNavigationCallbacks(mNavigationListAdapter, this);
it is possible to just request the view for the navigation list from the adapter with getLastParentView()