item click in menu drawing not working - java

I'm trying to make a navigation drawer that opens a new activity when the user intent an item.
I don't know how to do this?
There is 5 items in my drawer and I want each of them to open a different activity using intent not fragment .
when i click to the item anythink do , i need to go in other activity using intent
My code is the following
public class menu extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
TextView tt1 , txtnom , txtadress;
Typeface ty;
ViewPager viewp;
TabLayout tab;
ImageView img;
private DrawerLayout mdrawer;
private ActionBarDrawerToggle mtoggle;
private int[] tabIcons = {
R.drawable.ic_tablayout_tache,
R.drawable.ic_ic_tablayout_rendez,
R.drawable.ic_tablayout_eve,
R.drawable.ic_projettab
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Toolbar tol = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(tol);
getSupportActionBar().setTitle("");
tt1 = (TextView) findViewById(R.id.textbar);
ty = Typeface.createFromAsset(getAssets(), "fonts/BALOOBHAI-REGULAR.TTF");
tt1.setTypeface(ty);
mdrawer = (DrawerLayout) findViewById(R.id.drawerlayout);
mtoggle = new ActionBarDrawerToggle(this, mdrawer, R.string.ouvrir, R.string.fermer);
mdrawer.addDrawerListener(mtoggle);
mtoggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
viewp = (ViewPager) findViewById(R.id.viewpage);
tab = (TabLayout) findViewById(R.id.tablayout);
setupViewPager(viewp);
tab.setupWithViewPager(viewp);
setupTabIcons();
NavigationView navigationView = (NavigationView)findViewById(R.id.navview);
View header = LayoutInflater.from(this).inflate(R.layout.header_menu , null);
navigationView.addHeaderView(header);
navigationView.setNavigationItemSelectedListener(this);
img = (ImageView)header.findViewById(R.id.pic);
txtnom = (TextView)header.findViewById(R.id.textnom);
txtadress = (TextView)header.findViewById(R.id.textadr);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null){
Picasso.with(getApplicationContext()).load(user.getPhotoUrl()).transform(new CircleTransform()).into(img);
String name = user.getDisplayName();
String email = user.getEmail();
txtnom.setText(name);
txtadress.setText(email);
} else {
gopagelogin();
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mtoggle.onOptionsItemSelected(item)) {
return true;
}
int id = item.getItemId();
if ( id == R.id.dec) {
alertmsg();
}
return super.onOptionsItemSelected(item);
}
public void runThis(View v) {
Intent ii = new Intent(menu.this, partietache.class);
startActivity(ii);
}
public void Rendezvous(View v) {
Intent intent = new Intent(menu.this, partierendezvous.class);
startActivity(intent);
}
public void Evenement(View v) {
Intent intent = new Intent(menu.this, partieevenement.class);
startActivity(intent);
}
public void Projet(View v) {
Intent intent = new Intent(menu.this, partieprojet.class);
startActivity(intent);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new Tachefragment(), "Tâches");
adapter.addFragment(new RendezvousFragment(), "Rendez-vous");
adapter.addFragment(new Evenementfragment(), "Événements");
adapter.addFragment(new ProjetFragment(), "Projets");
viewPager.setAdapter(adapter);
}
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.para) {
Intent i = new Intent(menu.this, settingmenu.class);
startActivity(i);
} else if (id == R.id.prof) {
Toast.makeText(this, "clicked", Toast.LENGTH_SHORT).show();
}
mdrawer.closeDrawer(GravityCompat.START);
return true;
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String taches) {
mFragmentList.add(fragment);
mFragmentTitleList.add(taches);
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
private void setupTabIcons() {
tab.getTabAt(0).setIcon(tabIcons[0]);
tab.getTabAt(1).setIcon(tabIcons[1]);
tab.getTabAt(2).setIcon(tabIcons[2]);
tab.getTabAt(3).setIcon(tabIcons[3]);
}
private void gopagelogin() {
Intent ii = new Intent(this , login.class);
ii.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(ii);
}
private void alertmsg() {
AlertDialog.Builder alert = new AlertDialog.Builder(menu.this);
alert.setTitle("Déconnexion ?");
alert.setMessage("voulez-vous déconnecter?");
alert.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
FirebaseAuth.getInstance().signOut();
gopagelogin();
}
});
alert.setNegativeButton("Non", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.cancel();
}
});
alert.show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.deconnexion , menu);
return true;
}}
My xml code :
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawerlayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/mytoolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/AppTabLayout"
app:tabTextAppearance="#style/AppTabTextAppearance"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout" />
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="start"
android:background="#ededed"
app:itemIconTint="#000000"
app:itemTextColor="#000000"
app:menu="#menu/menudeb">
</android.support.design.widget.NavigationView>
<RelativeLayout xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignEnd="#+id/material_design_android_floating_action_menu"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/material_design_android_floating_action_menu">
<TextView
android:id="#+id/textbar"
android:layout_width="125dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginBottom="100dp"
android:layout_marginLeft="125dp"
android:layout_marginTop="11dp"
android:gravity="center"
android:text="WACKTY"
android:textColor="#01b698"
android:textSize="24dp" />
<RelativeLayout
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textmenu">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="#android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#ffffff"
fab:menu_colorPressed="#ffffff"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_size="normal"
fab:menu_icon="#drawable/ic_action_plus"
fab:menu_labels_colorNormal="#c4c0c0"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="0dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="#anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="1dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="#anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="false"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#000000"
fab:menu_labels_textSize="14sp"
fab:menu_openDirection="up">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/projet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_projeticon"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Projet"
android:onClick="Projet"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/événement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_eventicon"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Événement"
android:onClick="Evenement"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/rendezvous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Rendezvous"
android:src="#drawable/ic_action_rendez"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Rendez-Vous"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/tache"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="runThis"
android:src="#drawable/ic_action_task"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Tâches"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
</RelativeLayout>
Menu xml :
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="#+id/prof"
android:icon="#drawable/ic_user"
android:title="Profile"
/>
<item
android:id="#+id/proj"
android:icon="#drawable/ic_project"
android:title="Projets"/>
<item
android:id="#+id/para"
android:icon="#drawable/ic_action_set"
android:title="Parametres" />
</group>
<item android:title="Compte">
<menu>
<item
android:id="#+id/dec"
android:icon="#drawable/ic_action_set"
android:title="Déconnexion"/>
</menu>
</item>
</menu>

In your overrided onNavigationItemSelected(MenuItem item) method you have to getItemId and on the selected Item you have to open activity through intent.
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.ItemId) {
Intent i = new Intent(YourActivityName.this, OtherActivity.class);
startActivity(i);
}
mdrawer.closeDrawer(GravityCompat.START);
return true;
}
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawerlayout"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/mytoolbar" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/AppTabLayout"
app:tabTextAppearance="#style/AppTabTextAppearance"
app:tabMode="fixed" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout" />
</LinearLayout>
<RelativeLayout xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignEnd="#+id/material_design_android_floating_action_menu"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/material_design_android_floating_action_menu">
<TextView
android:id="#+id/textbar"
android:layout_width="125dp"
android:layout_height="30dp"
android:layout_gravity="center"
android:layout_marginBottom="100dp"
android:layout_marginLeft="125dp"
android:layout_marginTop="11dp"
android:gravity="center"
android:text="WACKTY"
android:textColor="#01b698"
android:textSize="24dp" />
<RelativeLayout
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textmenu">
<com.github.clans.fab.FloatingActionMenu
android:id="#+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
fab:menu_animationDelayPerItem="55"
fab:menu_backgroundColor="#android:color/transparent"
fab:menu_buttonSpacing="0dp"
fab:menu_colorNormal="#ffffff"
fab:menu_colorPressed="#ffffff"
fab:menu_colorRipple="#99d4d4d4"
fab:menu_fab_size="normal"
fab:menu_icon="#drawable/ic_action_plus"
fab:menu_labels_colorNormal="#c4c0c0"
fab:menu_labels_colorPressed="#444"
fab:menu_labels_colorRipple="#66efecec"
fab:menu_labels_cornerRadius="0dp"
fab:menu_labels_ellipsize="none"
fab:menu_labels_hideAnimation="#anim/fab_slide_out_to_right"
fab:menu_labels_margin="0dp"
fab:menu_labels_maxLines="-1"
fab:menu_labels_padding="1dp"
fab:menu_labels_position="left"
fab:menu_labels_showAnimation="#anim/fab_slide_in_from_right"
fab:menu_labels_showShadow="false"
fab:menu_labels_singleLine="false"
fab:menu_labels_textColor="#000000"
fab:menu_labels_textSize="14sp"
fab:menu_openDirection="up">
<com.github.clans.fab.FloatingActionButton
android:id="#+id/projet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_projeticon"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Projet"
android:onClick="Projet"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/événement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_eventicon"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Événement"
android:onClick="Evenement"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/rendezvous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="Rendezvous"
android:src="#drawable/ic_action_rendez"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Rendez-Vous"
fab:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="#+id/tache"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="runThis"
android:src="#drawable/ic_action_task"
fab:fab_colorNormal="#ffffff"
fab:fab_colorPressed="#444"
fab:fab_label="Tâches"
fab:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
</RelativeLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="#+id/navview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="start"
android:background="#ededed"
app:itemIconTint="#000000"
app:itemTextColor="#000000"
app:menu="#menu/menudeb">
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

Related

Navigation Drawer closing on click event

I am unable to click any of my menu items, I cannot swipe from right to left to close the drawer, although, whenever it is opened and I click on the screen it immediately closes.
I have pretty much tried every answer posted to similar questions here on stack overflow and Github:
public class BottomActivity extends AppCompatActivity
implements GestureOverlayView.OnGesturePerformedListener {
RadioGroup radioGroup;
RadioButton Rd1, Rd2, Rd3, Rd4;
DrawerLayout drawer;
#SuppressLint({"RtlHardcoded", "ClickableViewAccessibility"})
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_bottom );
new GestureOverlayView( this );
Objects.requireNonNull( getSupportActionBar() ).setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM );
getSupportActionBar().setCustomView( R.layout.abs_layout_home );
radioGroup = findViewById( R.id.radioGroup );
Rd1 = findViewById( R.id.radioButton );
Rd2 = findViewById( R.id.radioButton2 );
Rd3 = findViewById( R.id.radioButton3 );
Rd4 = findViewById( R.id.radioButton4 );
radioGroup.setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (Rd1.isChecked()) {
Intent intent = new Intent( getApplicationContext(), BottomActivity.class );
startActivity( intent );
}
if (Rd2.isChecked()) {
Intent intent1 = new Intent( getApplicationContext(), DashBoard.class );
startActivity( intent1 );
}
if (Rd3.isChecked()) {
Intent intent2 = new Intent( getApplicationContext(), SettingsActivity.class );
startActivity( intent2 );
} else {
if (Rd4.isChecked()) {
Intent intent3 = new Intent( getApplicationContext(), Messages.class );
startActivity( intent3 );
}
}
}
} );
}
#Override
public void onBackPressed() {
if (drawer.isDrawerOpen( GravityCompat.START )) {
drawer.closeDrawer( GravityCompat.START );
} else {
super.onBackPressed();
}
}
public void onDrawerSlide() {
DrawerLayout drawerLayout = findViewById( R.id.DrawerLayout);
drawerLayout.addDrawerListener(
new DrawerLayout.DrawerListener() {
#Override
public void onDrawerSlide(#NonNull View view, float v) {
}
#Override
public void onDrawerOpened(#NonNull View view) {
}
#Override
public void onDrawerClosed(#NonNull View view) {
}
#Override
public void onDrawerStateChanged(int i) {
}
}
);
}
#Override
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.nav_profile:
startActivity( new Intent(BottomActivity.this, ProfileActivity.class));
return true;
case R.id.nav_settings:
startActivity( new Intent( BottomActivity.this, SettingsActivity.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
Here is my navigation drawer XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start"
tools:openNavigationView="start"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
android:minHeight="?attr/actionBarSize"
app:layout_collapseMode="pin"/>
</android.support.design.widget.CollapsingToolbarLayout>
<include
layout="#layout/app_bar_nav_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
Here is my activities XML code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:elevation="10dp"
android:foregroundGravity="center"
android:gravity="center"
android:orientation="vertical"
tools:context=".BottomActivity"
tools:targetApi="lollipop"
app:layout_collapseMode="parallax">
<include
android:id="#+id/include"
layout="#layout/activity_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="#+id/radioButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/iconColor"
android:checked="true"
android:drawableTop="#drawable/ic_home_black_24dp"
android:padding="10dp"
android:tag="1"
android:text="#string/home"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_notifications_black_24dp"
android:padding="10dp"
android:text="#string/notifications"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconColor"
android:drawableTop="#drawable/ic_people_icon"
android:padding="10dp"
android:text="#string/People"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#null"
android:buttonTint="#color/uiconcolor"
android:drawableTop="#drawable/ic_msg_icon"
android:padding="10dp"
android:text="#string/Messages"
android:textAlignment="center"
android:textColor="#color/color"
android:textSize="12sp"/>
</RadioGroup>
</android.support.design.widget.CoordinatorLayout>
In BottomActivity add this in your onCreate:
NavigationView nav_view;
nav_view = findViewById(R.id.nav_view); //select nav_view from activity_drawer_layout
nav_view.setNavigationItemSelectedListener(this);
In activity_drawer_layout.xml put the NavigationView above the closing tag for the DrawerLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DrawerLayout"
android:id="#+id/DrawerLayout">
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="0dp"
android:layout_height="0dp" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="0dp"
android:layout_height="673dp"
android:padding="16dp"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/age"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:layout_constraintBottom_toBottomOf="#+id/nav_header" />
<include
android:id="#+id/include"
layout="#layout/app_bar_nav_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="start"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
app:headerLayout="#layout/nav_header_nav_drawer"
app:menu="#menu/activity_nav_drawer_drawer" />
</android.support.v4.widget.DrawerLayout>

Android Popup Menu fill parent

I try set my popup menu in way to fill hole item on grid. Currently it look like on attached first picture and the next one is effect which I would like to have.
My code:
private void showPopupMenu(View view) {
// inflate menu
ContextThemeWrapper ctw = new ContextThemeWrapper(context, R.style.PopupMenu);
PopupMenu popup = new PopupMenu(ctw, view);
Menu menu = popup.getMenu();
menu.add(Menu.NONE, 1, Menu.NONE, "Remove");
menu.add(Menu.NONE, 2, Menu.NONE, "Block");
popup.setOnMenuItemClickListener(new MyMenuItemClickListener());
popup.show();
}
Could you please point me to right direction to achieve effect from project?
Demo App for your requirment by using PopupWindow. Preview
You can add list in it or customize it according to your needs.
MainActivity
public class MainActivity extends Activity {
boolean isClicked = true;
PopupWindow popUpWindow;
RelativeLayout relative;
ImageView btnClickHere;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
relative = (RelativeLayout) findViewById(R.id.relative);
popUpWindow = new PopupWindow(this);
popUpWindow.setContentView(getLayoutInflater().inflate(R.layout.popup_design, null));
popUpWindow.getContentView().findViewById(R.id.textViewa).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "PopItemClicked", Toast.LENGTH_LONG).show();
}
});
btnClickHere = (ImageView) findViewById(R.id.imageView);
btnClickHere.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (isClicked) {
isClicked = false;
popUpWindow.setHeight(relative.getHeight());
popUpWindow.setWidth(relative.getWidth());
popUpWindow.showAsDropDown(relative, 0, -relative.getHeight());
} else {
isClicked = true;
popUpWindow.dismiss();
}
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sohailzahid.testapp.MainActivity">
<RelativeLayout
android:id="#+id/relative"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#color/colorAccent"
tools:layout_editor_absoluteX="150dp"
tools:layout_editor_absoluteY="150dp">
<ImageView
android:id="#+id/imageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="#android:drawable/arrow_down_float" />
</RelativeLayout>
</RelativeLayout>
popup_design.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F93567">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textViewa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Block"
android:textColor="#ffffff"
android:textSize="20dp" />
<TextView
android:id="#+id/textVsiewa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Add to friends"
android:textColor="#ffffff"
android:textSize="20dp" />
<TextView
android:id="#+id/textViesw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="Remove"
android:textColor="#ffffff"
android:textSize="20dp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:src="#android:drawable/arrow_down_float" />
</RelativeLayout>
Try this
popup.getWindow().getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
popup.getWindow().getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;

Android List View shows items, but text is empty

I am experiencing a very weird issue where I am unable to view any text/data, but it clearly shows the number of items in the list.
I have confirmed that dataList has data, and I am able to get the exact same string that I set after debugging.
Parent Fragment:
ListView InboxListView = (ListView) view.findViewById(R.id.listViewInbox);
InboxAdapter adapter = new InboxAdapter(mActivity, R.layout.activity_inbox_item, dataList, NotificationInbox.this);
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SwipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:padding="15dp"
android:id="#+id/searchBarInbox"
android:hint="Search"
android:layout_height="wrap_content" />
<ListView
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_marginTop="49dp"
android:id="#+id/listViewInbox" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Adapter: http://pastebin.com/mSUrdLcW << CLICK
public class InboxAdapter extends ArrayAdapter<InboxBO> {
NotificationInbox fragment;
Context context;
List<InboxBO> inboxForSharedPref;
List<InboxBO> inboxList;
int layoutResID;
SharedPreferences prefs;
private ArrayList<InboxBO> inboxarraylist;
private SparseBooleanArray mSelectedItemIds;
public InboxAdapter(Context context, int layoutResourceID, List<InboxBO> objs, NotificationInbox fragment) {
super(context, layoutResourceID, objs);
mSelectedItemIds = new SparseBooleanArray();
this.context = context;
this.inboxList = objs;
this.layoutResID = layoutResourceID;
this.inboxarraylist = new ArrayList<InboxBO>();
this.inboxarraylist.addAll(inboxList);
this.fragment = fragment;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
inboxHolder inboxholder;
View view = convertView;
if (view == null) {
view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(layoutResID, parent, false);
//LayoutInflater inflater = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
//LayoutInflater inflater = LayoutInflater.from(getContext());
//inflater.inflate(R.layout.activity_inbox_item, null);
inboxholder = new inboxHolder();
//view = inflater.inflate(layoutResID, parent, false);
prefs = context.getSharedPreferences(
Constants.PREF_NAME, 0);
inboxholder.swipeLayout = (SwipeLayout)view.findViewById(R.id.swipe_layout);
inboxholder.senderNameText = (TextView) view.findViewById(R.id.senderNameText);
inboxholder.pushDateText = (TextView) view.findViewById(R.id.pushDateText);
inboxholder.pushTimeText = (TextView) view.findViewById(R.id.pushTimeText);
inboxholder.messageText = (TextView) view.findViewById(R.id.messageText);
inboxholder.delete = (TextView)view.findViewById(R.id.delete);
inboxholder.itemLayout = (RelativeLayout) view.findViewById(R.id.relativeViewInbox);
inboxholder.swipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
inboxholder.delete.setOnClickListener(onDeleteListener(position, inboxholder));
view.setTag(inboxholder);
}
else {
inboxholder = (inboxHolder) view.getTag();
}
InboxBO mItem = inboxList.get(position);
if(mItem!=null){
inboxholder.senderNameText.setText((String)mItem.getTitle());
inboxholder.pushDateText.setText(new Date().toString());
inboxholder.pushTimeText.setText(new Date().toString());
inboxholder.messageText.setText((String)mItem.getMessage());
}
return view;
}
// For swipe action
private View.OnClickListener onDeleteListener(final int position, final inboxHolder holder) {
return new View.OnClickListener() {
#Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
context);
alert.setTitle("Delete Message");
alert.setMessage("Are you sure you wish to delete this message?");
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
inboxList.remove(position);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
Toast.makeText(context, "Message Deleted!",
Toast.LENGTH_SHORT).show();
holder.swipeLayout.close();
fragment.retrieveMessage();
dialog.dismiss();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
};
}
// Algorithm to filter out listview based on text changed in listview searchbox
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
inboxList.clear();
if (charText.length() == 0) {
inboxList.addAll(inboxarraylist);
}
else
{
for (InboxBO ilist : inboxarraylist)
{
/*if (ilist.getDate().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getSendername().toLowerCase(Locale.getDefault()).contains(charText))
{
inboxList.add(ilist);
}*/
if(ilist.getTitle().toLowerCase(Locale.getDefault()).contains(charText) || ilist.getMessage().toLowerCase(Locale.getDefault()).contains(charText) ){
inboxList.add(ilist);
}
}
}
notifyDataSetChanged();
}
public static class inboxHolder {
TextView senderNameText, pushDateText, pushTimeText, messageText, delete, title;
RelativeLayout itemLayout;
private SwipeLayout swipeLayout;
}
// Methods below are for multi-deletion
public void toggleSelection(int position) {
selectView(position, !mSelectedItemIds.get(position));
}
// Remove selection after unchecked
public void remove(InboxBO object) {
inboxList.remove(object);
Gson gson = new Gson();
inboxForSharedPref = fragment.getStoredMessages();
inboxForSharedPref = inboxList;
String jsonSavePref = gson.toJson(inboxForSharedPref);
fragment.commitToStoredList(jsonSavePref);
notifyDataSetChanged();
}
// Item checked on selection
public void selectView(int position, boolean value) {
if (value)
mSelectedItemIds.put(position, value);
else
mSelectedItemIds.delete(position);
notifyDataSetChanged();
}
// Get number of selected item
public int getSelectedCount() {
return mSelectedItemIds.size();
}
public SparseBooleanArray getSelectedIds() {
return mSelectedItemIds;
}
public void removeSelection() {
mSelectedItemIds = new SparseBooleanArray();
notifyDataSetChanged();
}
}
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
EDIT: Screenshot added
EDIT2: Clarified parent fragment calling the adapter.
EDIT3: I did a temporary fix. Apparently the RelativeLayout and the Linear Layout in the AdapterXML were the cause of my misery. I'm not exactly sure why, though. I think it's the RelativeLayout and the LinearLayout somehow not displaying the text. Removing those two tags will display the texts in a linear fashion.
Try this
Adapter XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bottom_wrapper"
android:layout_width="100dp"
android:layout_gravity="start"
android:layout_height="match_parent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ff0000">
<TextView
android:id="#+id/delete"
android:text="Delete"
android:textSize="18sp"
android:textColor="#color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:background="?android:attr/activatedBackgroundIndicator"
android:orientation="vertical"
android:layout_width="match_parent"
android:id="#+id/relativeViewInbox"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:text="SenderName"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="left"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/senderNameText"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:text="PushDate"
android:gravity="right"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"
android:layout_height="match_parent"
android:id="#+id/pushDateText" />
</LinearLayout>
<TextView
android:layout_width="320dp"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:text="Message..."
android:id="#+id/messageText"
android:textColor="#color/black"
android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="end"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/linearLayout" />
<TextView
android:layout_width="match_parent"
android:text="PushTime"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="right"
android:layout_weight="1"
android:textColor="#color/black"
android:layout_height="match_parent"
android:id="#+id/pushTimeText"
android:layout_alignTop="#+id/messageText" />
</RelativeLayout>

ScrollView overlaps ActionBar, prevents buttons selected

When I change the layout of a fragment within an activity, the menu options in the action bar seem to stop working. The buttons (Search icon and NavDrawer icon) become unresponsive.
This is the layout file of the fragment with the working menu options:
activity_login.xml (working)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".LoginFragment"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login."
android:id="#+id/login_title_text"
android:layout_alignParentTop="true"
android:textSize="40sp"
android:layout_marginTop="100dp"
android:fontFamily="sans-serif-light"
android:textColor="#color/colorAlt"
android:layout_centerHorizontal="true" />
<!-- E-mail section -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="E-mail address"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:ems="10"
android:id="#+id/login_emailField"
android:layout_above="#+id/login_passwordField" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/register_email_icon"
android:layout_alignBottom="#id/login_emailField"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"/>
<!-- Password section -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/register_password_icon"
android:layout_alignBottom="#id/login_passwordField"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginTop="10dp"
android:hint="Password"
android:id="#+id/login_passwordField"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="25dp" />
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/login_login_button"
android:layout_gravity="center_vertical"
android:layout_below="#+id/login_passwordField"
android:layout_marginBottom="29dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
card_view:cardBackgroundColor="#E91E63"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="6dp">
<TextView
android:id="#+id/material_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:layout_gravity="center_horizontal"
android:textColor="#FFF"
android:textSize="19sp"
android:fontFamily="sans-serif-medium"
android:text="Login" />
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Forgotten your username or password?"
android:layout_below="#id/login_login_button"
android:gravity="center"
android:layout_centerHorizontal="true"
android:id="#+id/login_footer_text"
android:layout_marginTop="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Tap here"
android:textColor="#000000"
android:layout_below="#id/login_footer_text"
android:gravity="center"
android:layout_centerHorizontal="true"
android:id="#+id/loginForgottenTapText"
android:layout_marginTop="20dp"/>
</RelativeLayout>
</LinearLayout>
This is the layout file that seems to break the buttons:
activity_login.xml (non-working)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".LoginFragment"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Login."
android:id="#+id/login_title_text"
android:layout_alignParentTop="true"
android:textSize="40sp"
android:layout_marginTop="100dp"
android:fontFamily="sans-serif-light"
android:textColor="#color/colorAlt"
android:layout_centerHorizontal="true" />
<!-- E-mail section -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="E-mail address"
android:layout_marginLeft="50dp"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp"
android:ems="10"
android:id="#+id/login_emailField"
android:layout_below="#+id/login_title_text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/register_email_icon"
android:layout_alignBottom="#id/login_emailField"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"/>
<!-- Password section -->
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:layout_marginTop="10dp"
android:hint="Password"
android:layout_below="#id/login_emailField"
android:id="#+id/login_passwordField"
android:layout_marginLeft="50dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="25dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/register_password_icon"
android:layout_alignBottom="#id/login_passwordField"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp"/>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/login_login_button"
android:layout_gravity="center_vertical"
android:layout_below="#+id/login_passwordField"
android:layout_marginBottom="29dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
card_view:cardBackgroundColor="#E91E63"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="6dp">
<TextView
android:id="#+id/material_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="13dp"
android:paddingBottom="13dp"
android:layout_gravity="center_horizontal"
android:textColor="#FFF"
android:textSize="19sp"
android:fontFamily="sans-serif-medium"
android:text="Login" />
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Forgotten your username or password?"
android:layout_below="#id/login_login_button"
android:gravity="center"
android:layout_centerHorizontal="true"
android:id="#+id/login_footer_text"
android:layout_marginTop="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Tap here"
android:textColor="#000000"
android:layout_below="#id/login_footer_text"
android:gravity="center"
android:layout_centerHorizontal="true"
android:id="#+id/loginForgottenTapText"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</ScrollView>
MainActivity.java
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, LoginFragment.OnLoginCallback {
MenuItem register;
MenuItem login;
MenuItem logout;
MenuItem completeListing;
MenuItem expiredListing;
MenuItem activeListing;
NavigationView navigationView;
UserCredentialHandler userStatus;
protected static final String KEY_USER_STATUS = "USER_STATUS";
protected static final String USER_PREFS = "userNamePrefs";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userStatus = new UserCredentialHandler();
final HomeFragment homeFragment = new HomeFragment();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), CreateListingActivity.class);
startActivity(i);
}
});
navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
getMenuItems(navigationView);
if(userStatus.checkIfUserIsLoggedIn(getApplicationContext())){
userStatus.setNavHeaderOnLogin(getApplicationContext(), navigationView);
updateNavDrawer("login", register, login, logout, expiredListing, completeListing, activeListing);
} else {
userStatus.setNavHeaderOnLogout(navigationView);
updateNavDrawer("logout", register, login, logout, expiredListing, completeListing, activeListing);
}
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.main_container,homeFragment);
fragmentTransaction.commit();
}
#Override
public void onLoginSuccess() {
HomeFragment homeFragment = new HomeFragment();
userStatus.setNavHeaderOnLogin(getApplicationContext(), navigationView);
updateNavDrawer("login",register,login,logout, expiredListing, completeListing, activeListing);
register.setVisible(false);
login.setVisible(false);
logout.setVisible(true);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
fragmentTransaction.replace(R.id.main_container,homeFragment);
fragmentTransaction.commit();
}
#Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
getSupportFragmentManager().popBackStack();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_activity_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.search_mag_icon){
SearchFragment searchFragment = new SearchFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_container, searchFragment)
.addToBackStack(null)
.commit();
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_register) {
final RegisterFragment registerFragment = new RegisterFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_container, registerFragment)
.addToBackStack(null)
.commit();
} else if (id == R.id.nav_login) {
final LoginFragment loginFragment = new LoginFragment();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.main_container, loginFragment)
.addToBackStack(null)
.commit();
} else if(id == R.id.nav_logout) {
userStatus.logoutUser(getApplicationContext());
userStatus.setNavHeaderOnLogout(navigationView);
updateNavDrawer("logout",register,login,logout, expiredListing, completeListing, activeListing);
} else if (id == R.id.nav_my_listings) {
// navigate to my listings
} else if (id == R.id.nav_how) {
// navigate to how it works page
} else if (id == R.id.nav_help) {
// navigate to help page
} else if (id == R.id.nav_contact_us) {
// navigate to contact page,
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private void updateNavDrawer(String action, MenuItem register, MenuItem login, MenuItem logout, MenuItem expiredListing, MenuItem completeListing, MenuItem activeListing){
if(action=="login"){
register.setVisible(false);
login.setVisible(false);
logout.setVisible(true);
completeListing.setVisible(true);
activeListing.setVisible(true);
expiredListing.setVisible(true);
} else {
register.setVisible(true);
login.setVisible(true);
logout.setVisible(false);
completeListing.setVisible(false);
activeListing.setVisible(false);
expiredListing.setVisible(false);
}
}
private void getMenuItems(NavigationView nv){
register = nv.getMenu().getItem(0);
login = nv.getMenu().getItem(1);
logout = nv.getMenu().getItem(2);
activeListing = nv.getMenu().getItem(3);
completeListing = nv.getMenu().getItem(4);
expiredListing = nv.getMenu().getItem(5);
}
}
I cannot seem to workout why changing the layout is breaking the ActionBar menu options, any help would be appreciated.
Edit:
Changing the <ScrollView> element to <LinearLayout> seems to solve it but I need a ScrollView. The ScrollView seems to overlap the ActionBar and is on the top.
Try setting android:layout_height on the ScrollView to "match_parent" instead of "wrap_content"

implementation of listViews and images

My problem is, i want to implement a activity with a list and image and in the bottom of image there is four text .When I am going to open my app it has to show one selected text with its related image and list as default.when clicking on rest of the text it has to show their related list and images in the same activity respectively.Since i am new to android please help me out.
Here is xml code
<RelativeLayout
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.5"
>
<ImageView
android:id="#+id/mainimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pestf"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pest Control"
android:id="#+id/pestf"
android:onClick="click1"
android:clickable="true"
android:textStyle="normal"
android:textSize="15dp"
android:textColor="#cf0c07"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/packf"
android:layout_marginLeft="5dp"
android:id="#+id/packf"
android:onClick="click1"
android:clickable="true"
android:textStyle="normal"
android:textSize="15dp"
android:textColor="#cf0c07"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cleaning"
android:layout_marginLeft="5dp"
android:id="#+id/cleanf"
android:onClick="click1"
android:clickable="true"
android:textStyle="normal"
android:textSize="15dp"
android:textColor="#cf0c07"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Landscaping"
android:id="#+id/landf"
android:onClick="click1"
android:clickable="true"
android:layout_marginLeft="5dp"
android:textStyle="normal"
android:textSize="15dp"
android:textColor="#cf0c07"/>
</LinearLayout>
</RelativeLayout>
<ListView
android:id="#+id/lst"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/ll_pest"
android:layout_weight="2.2"
android:background="#FFFFFF"
>
</ListView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/lst"
android:layout_weight="3.5"
android:gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="3dp"
android:layout_alignParentBottom="true"
android:background="#drawable/border_layout">
<TextView
android:id="#+id/txt_pest_Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#FFFFFF"
android:text="#string/btn7"
android:drawablePadding="5dp"
android:drawableTop="#drawable/icon7"
android:textStyle="bold"
android:textColor="#000000"
/>
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#82020202" />
<TextView
android:id="#+id/txt_pest_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:text="#string/btn8"
android:drawablePadding="5dp"
android:drawableTop="#drawable/icon8"
android:textStyle="bold"
android:textColor="#000000"
/>
</LinearLayout>
Here is Activity code
public class demo2 extends AppCompatActivity {
TextView tv1,tv2,tv3,tv4,txtEmail,txtPhone;
ListView lv;
ImageView img;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo2);
String[] adobe_products = getResources().getStringArray(R.array.adobe_products);
lv = (ListView) findViewById(R.id.lst);
img = (ImageView) findViewById(R.id.mainimage);
txtEmail=(TextView)findViewById(R.id.txt_pest_Email);
txtPhone=(TextView)findViewById(R.id.txt_pest_phone);
tv1 = (TextView) findViewById(R.id.text1);
tv2 = (TextView) findViewById(R.id.text2);
tv3 = (TextView) findViewById(R.id.text3);
tv4 = (TextView) findViewById(R.id.text4);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, adobe_products));
tv1.setTextColor(getResources().getColor(R.color.blue));
txtPhone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String mobileNo = "08042589999";
String uri = "tel:" + mobileNo.trim();
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse(uri));
startActivity(intent);
}
});
txtEmail.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(demo2.this, Booknow.class);
// sending data to new activity
i.putExtra("flag",true);
i.putExtra("cat",1);
startActivity(i);
}
});
// Inflate the layout for this fragment
}
public void click2(View v){
img.setBackgroundResource(R.drawable.packers);
String[] countries = getResources().getStringArray(R.array.country);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item1, countries));
tv2.setTextColor(getResources().getColor(R.color.blue));
tv1.setTextColor(getResources().getColor(R.color.red));
tv3.setTextColor(getResources().getColor(R.color.red));
tv4.setTextColor(getResources().getColor(R.color.red));
}
public void click1(View v){
img.setBackgroundResource(R.drawable.pestf);
String[] adobe = getResources().getStringArray(R.array.adobe_products);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item1, adobe));
tv1.setTextColor(getResources().getColor(R.color.blue));
tv2.setTextColor(getResources().getColor(R.color.red));
tv3.setTextColor(getResources().getColor(R.color.red));
tv4.setTextColor(getResources().getColor(R.color.red));
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Launching new Activity on selecting single List Item
Intent i = new Intent(demo2.this, BedbugControl.class);
// sending data to new activity
i.putExtra("position", position);
startActivity(i);
}
});
}
public void click3(View v){
img.setBackgroundResource(R.drawable.cleaningf);
String[] sweets = getResources().getStringArray(R.array.sweets);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item1, sweets));
tv3.setTextColor(getResources().getColor(R.color.blue));
tv1.setTextColor(getResources().getColor(R.color.red));
tv2.setTextColor(getResources().getColor(R.color.red));
tv4.setTextColor(getResources().getColor(R.color.red));
}
public void click4(View v) {
img.setBackgroundResource(R.drawable.landf);
String[] companies = getResources().getStringArray(R.array.company);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item1, companies));
tv4.setTextColor(getResources().getColor(R.color.blue));
tv1.setTextColor(getResources().getColor(R.color.red));
tv2.setTextColor(getResources().getColor(R.color.red));
tv3.setTextColor(getResources().getColor(R.color.red));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_demo2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Categories

Resources