Without Scrollview
I need the white space below the toolbar in the image above to be in a scrollview. But adding a scroll view results in this:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_newg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="none"
app:elevation="0dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:theme="#style/ToolbarTheme"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="32dp"
android:paddingStart="32dp"
android:paddingBottom="40dp"
android:paddingRight="16dp"
android:paddingEnd="16dp">
<android.support.design.widget.TextInputLayout
android:id="#+id/entry_home_TIL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp">
<android.support.design.widget.TextInputEditText
android:textSize="27sp"
android:ems="10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:id="#+id/entry_home" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/entry_away_TIL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp">
<android.support.design.widget.TextInputEditText
android:textSize="27sp"
android:ems="10"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/entry_away" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="#+id/entry_tourney_title_TIL"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp">
<EditText
android:hint="Tournament"
android:textSize="27sp"
android:ems="10"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/entry_tourney_title" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/newGameFields"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#000000"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_event_black_24dp"
android:drawableStart="#drawable/ic_event_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:text="Time"
android:clickable="true"
android:id="#+id/dateText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:textColor="#000000"
android:id="#+id/timeText"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:drawableLeft="#drawable/ic_clock_black_24dp"
android:drawableStart="#drawable/ic_clock_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingRight="30dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<View style="#style/Divider_Horz"/>
<EditText
android:hint="Location"
android:background="#null"
android:drawableLeft="#drawable/ic_place_black_24dp"
android:drawableStart="#drawable/ic_place_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/entry_location" />
<View style="#style/Divider_Horz"/>
<EditText
android:hint="Add starters"
android:background="#null"
android:drawableLeft="#drawable/ic_people_black_24dp"
android:drawableStart="#drawable/ic_people_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/entry_starters" />
<View style="#style/Divider_Horz"/>
<EditText
android:hint="Add note"
android:background="#null"
android:drawableLeft="#drawable/ic_short_text_black_24dp"
android:drawableStart="#drawable/ic_short_text_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/entry_notes" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
If you have ever used the google calendar app when adding an event I would like it to be like that.
Here is the relevant fragment code:
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import com.github.clans.fab.FloatingActionMenu;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* A simple {#link Fragment} subclass.
*/
public class NewGame extends Fragment {
//private static final String TAG = "AKDialogFragment";
EditText entryAway, entryHome;
private OnFragmentInteractionListener mListener;
private OnFragmentInteractionListener mListener2;
private static final int[] EDITTEXT_IDS = {
R.id.entry_home,
R.id.entry_away
};
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FloatingActionMenu fab = (FloatingActionMenu) getActivity().findViewById(R.id.material_design_android_floating_action_menu);
fab.setVisibility(View.GONE);
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_new_game, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar_newg);
toolbar.setTitle("");
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24px);
}
return rootView;
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
final TimePickerDialog timePicker;
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String formattedDate = sdf.format(c.getTime());
((TextView) getActivity().findViewById(R.id.dateText)).setText(formattedDate);
setTime12Hour(hour,minute);
TextView textViewDate = (TextView) getActivity().findViewById(R.id.dateText);
textViewDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
DialogFragment picker = new DatePickerFragment();
picker.show(getFragmentManager(), "datePicker");
}
});
TextView textViewTime = (TextView) getActivity().findViewById(R.id.timeText);
textViewTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
showTimePickerDialog(v);
}
});
String team = "West Albany";
EditText eTHome = (EditText) getActivity().findViewById(R.id.entry_home);
TextInputLayout eTHomeTil = (TextInputLayout) getActivity().findViewById(R.id.entry_home_TIL);
EditText eTAway = (EditText) getActivity().findViewById(R.id.entry_away);
TextInputLayout eTAwayTil = (TextInputLayout) getActivity().findViewById(R.id.entry_away_TIL);
switch (this.getTag()) {
case "home":
eTAwayTil.setHint("Away");
eTHome.setText(team);
break;
case "away":
eTHomeTil.setHint("Home");
eTAway.setText(team);
break;
case "tourney":
eTAwayTil.setHint("White");
eTHomeTil.setHint("Dark");
break;
case "scout":
eTHomeTil.setHint("Home");
eTAwayTil.setHint("Away");
break;
}
}
#Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
getActivity().getMenuInflater().inflate(R.menu.menu_ak, menu);
}
Thank you guys!
try removing android:fitsSystemWindows from AppBarLayout and add to NestedScrollView marginTop the height of AppBarLayout(you can calculate this height inside your Fragment, for example try setting marginTop to 200dp)
Related
Issue: Recycler View is not displaying. There is no error logged. The page is just blank. I did attempt to look at other similar Recycler View issues, but I have not been able to figure out the problem. I played around with the layout to make sure views were not overlapping but that did not fix the issue. I also looked through the java file but cannot find anything wrong with it. Any help will be appreciated. Thank you!
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:context=".Personal_Wall"
tools:openDrawer="end">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/coordinator_layout"
android:layout_width="match_parent"
android:background="#ffff"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
elevation="4dp"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#ffff"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
<ImageView
android:id="#+id/splashd_logo_button"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_gravity="right"
android:paddingRight="10dp"
android:src="#drawable/new_splashd_logo_black"
android:text="hapana_button" />
</androidx.appcompat.widget.Toolbar>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:overScrollMode="never"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="#+id/fragment-containter2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/edit_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="245dp"
android:layout_marginTop="250dp"
android:elevation="6dp"
android:background="#color/fui_transparent"
app:srcCompat="#drawable/ic_camera_icon" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/profile_place_holder"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="95dp"
android:elevation="4dp"
android:src="#drawable/grey_oval"
app:civ_border_color="#fff"
app:civ_border_width="5dp" />
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
card_view:cardBackgroundColor="#fff"
card_view:cardCornerRadius="8dp">
<ImageView
android:id="#+id/temporary_banner_personal_wall"
android:layout_width="380dp"
android:layout_height="250dp"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
app:srcCompat="#drawable/roundec_corner_rectangle_grey" />
</androidx.cardview.widget.CardView>
<TextView
android:id="#+id/personal_wall_text_first_name"
android:layout_width="193dp"
android:layout_height="wrap_content"
android:layout_marginLeft="158dp"
android:layout_marginTop="310dp"
android:layout_marginRight="50dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:inputType="textPersonName"
android:text="First"
android:textColor="#000"
android:textSize="30dp" />
<TextView
android:id="#+id/personal_wall_text_last_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="210dp"
android:layout_marginTop="310dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:inputType="textPersonName"
android:text="Last"
android:textColor="#000"
android:textSize="30dp" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/small_grey_circle"
android:layout_width="78dp"
android:layout_height="52dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="408dp"
android:src="#drawable/small_grey_circle" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Location: Washington D.C."
android:textSize="18dp"
android:textColor="#000"
android:fontFamily="#font/roboto_medium"
android:layout_marginTop="360dp"
android:layout_gravity="center_horizontal"
android:drawableLeft="#drawable/ic_profile_location_on_black_24dp"
>
</TextView>
<ImageView
android:id="#+id/personal_wall_post_something_box"
android:layout_width="290dp"
android:layout_height="69dp"
android:layout_marginLeft="95dp"
android:layout_marginTop="398dp"
android:src="#drawable/make_a_splash_oval" />
<TextView
android:id="#+id/assists_count"
android:layout_width="73dp"
android:layout_height="38dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_light"
android:text="Assists"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/assists_count_actual_number"
android:layout_width="73dp"
android:layout_height="38dp"
android:layout_marginLeft="45dp"
android:layout_marginTop="515dp"
android:textAlignment="center"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="3"
android:textColor="#000"
android:textSize="22dp" />
<TextView
android:id="#+id/followers_count"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="143dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_light"
android:text="Followers"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/followers_count_actual_number"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="144dp"
android:layout_marginTop="515dp"
android:textAlignment="center"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="2"
android:textColor="#000"
android:textSize="22dp" />
<TextView
android:id="#+id/splash_count"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="250dp"
android:layout_marginTop="550dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:fontFamily="#font/roboto_light"
android:text="Splashes"
android:textColor="#000"
android:textSize="15dp"
android:textAlignment="center"/>
<TextView
android:id="#+id/splash_count_actual_number"
android:layout_width="102dp"
android:layout_height="39dp"
android:textAlignment="center"
android:layout_marginLeft="250dp"
android:layout_marginTop="515dp"
android:layout_weight="0.5"
android:background="#android:color/transparent"
android:ems="10"
android:fontFamily="#font/roboto_bold"
android:text="5"
android:textColor="#000"
android:textSize="22dp" />
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginTop="590dp"
android:background="#android:color/darker_gray" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="488dp"
android:background="#E8E8E8" />
<TextView
android:id="#+id/testing_scrollview"
android:layout_width="102dp"
android:layout_height="39dp"
android:layout_marginLeft="293dp"
android:layout_marginTop="1400dp"
android:layout_weight="0.5"
android:fontFamily="#font/roboto_light"
android:text="TEST"
android:textColor="#000"
android:layout_marginBottom="120dp"
android:textSize="20dp"
android:textAlignment="center"/>
</FrameLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view_post_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="700dp"
android:layout_above="#+id/fragment_container_3">
</androidx.recyclerview.widget.RecyclerView>
<FrameLayout
android:id="#+id/fragment_container_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Main content -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemIconTint="#color/bottom_navigation_selected_color"
app:itemTextColor="#color/bottom_navigation_selected_color"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/bottom_navigation_menu"
app:itemIconSize="#dimen/bottom_navigation_icon_size"
/>
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/drawer_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
---------------------------------------------------------
package com.example.updatedhapana1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Picasso;
import com.theartofdev.edmodo.cropper.CropImage;
import com.theartofdev.edmodo.cropper.CropImageView;
import de.hdodenhof.circleimageview.CircleImageView;
import static com.example.updatedhapana1.Personal_Wall_Edit.Gallery_Pick2;
public class Personal_Wall extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Window window;
private DrawerLayout drawer;
private Bitmap bitmap;
private Uri uri;
private RecyclerView postList; //TRYING RECYCLER VIEW AGAIN AHHHHHHHHHH!
private String currentUserID;
private DatabaseReference UsersReference;
private CircleImageView profile_image;
private StorageReference UserProfileImageRef;
private FirebaseAuth mAuth;
private ImageView post_question;
private ImageButton edit_profile;
private DatabaseReference mDatabaseRef;
private ImageView banner_view;
private ImageButton splash_gallery;
FirebaseUser currentUser;
TextView mfirstname;
TextView mlastname;
TextView firstname_for_main_profile;
TextView lastname_for_main_profile;
NavigationView mNavigationView;
CircleImageView m_nav_header_profile_image;
CircleImageView profile_placeholder_personal_wall;
CircleImageView little_circle_personal_wall;
FirebaseDatabase mfirebaseDatabase;
final static int Gallery_Pick = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_personal__wall);
little_circle_personal_wall = findViewById(R.id.small_grey_circle); //this is to bring in the profile picture from the database
//////This change the status bar color and the status bar text color. I wanted the status bar to be white.//////////
if (Build.VERSION.SDK_INT > 21) {
window = this.getWindow();
window.setStatusBarColor(this.getResources().getColor(R.color.white));
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);// set status text dark
}
//////This change the status bar color and the status bar text color. I wanted the status bar to be white.//////////
mAuth = FirebaseAuth.getInstance();
currentUserID = mAuth.getCurrentUser().getUid();
UsersReference = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
UserProfileImageRef = FirebaseStorage.getInstance().getReference().child("Profile Images");
profile_image = findViewById(R.id.profile_place_holder_edit);
mDatabaseRef = FirebaseDatabase.getInstance().getReference("uploads");
profile_placeholder_personal_wall = findViewById(R.id.profile_place_holder);
banner_view = findViewById(R.id.temporary_banner_personal_wall);
//RECYCLERVIEW//
postList = (RecyclerView) findViewById(R.id.recycler_view_post_list);
postList.setHasFixedSize(true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setReverseLayout(true);
linearLayoutManager.setStackFromEnd(true);
postList.setLayoutManager(linearLayoutManager);
//RECYCLERVIEW//
----------------------------------------------------
#Override
protected void onStart() {
super.onStart();
FirebaseRecyclerOptions<Posts> options =
new FirebaseRecyclerOptions.Builder<Posts>()
.setQuery(UsersReference, Posts.class)
.build();
FirebaseRecyclerAdapter<Posts,FindPostsViewHolder> adapter =
new FirebaseRecyclerAdapter<Posts, FindPostsViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull FindPostsViewHolder findPostsViewHolder, int i, #NonNull Posts posts)
{
findPostsViewHolder.first_name.setText(posts.getFirst_name());
findPostsViewHolder.last_name.setText(posts.getLast_name());
findPostsViewHolder.post_date.setText(posts.getPost_date());
findPostsViewHolder.post_body_text.setText(posts.getPost_body_text());
}
#NonNull
#Override
public FindPostsViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.post_layout_2, viewGroup, false);
FindPostsViewHolder viewHolder = new FindPostsViewHolder(view);
return viewHolder;
}
};
postList.setAdapter(adapter);
adapter.startListening();
}
public static class FindPostsViewHolder extends RecyclerView.ViewHolder
{
TextView first_name, last_name, post_body_text, post_date;
public FindPostsViewHolder(#NonNull View itemView)
{
super(itemView);
first_name = itemView.findViewById(R.id.post_first_name);
last_name = itemView.findViewById(R.id.post_last_name);
post_date = itemView.findViewById(R.id.post_date_and_time);
post_body_text = itemView.findViewById(R.id.the_post);
}
}
----------------------------------------------
package com.example.updatedhapana1;
public class Posts
{
public String first_name, last_name, post_body_text, post_date;
//this is an empty contstructor- this is required//
public Posts ()
{
}
//this is an empty contstructor- this is required//
public Posts(String first_name, String last_name, String post_body_text, String post_date) {
this.first_name = first_name;
this.last_name = last_name;
this.post_body_text = post_body_text;
this.post_date = post_date;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getPost_body_text() {
return post_body_text;
}
public void setPost_body_text(String post_body_text) {
this.post_body_text = post_body_text;
}
public String getPost_date() {
return post_date;
}
public void setPost_date(String post_date) {
this.post_date = post_date;
}
}
I haven't tested your code, but this is what I suspect. From your XML it seems like you have linear layout and recycler view in 2 separate components and your LinearLayout is match_parent.
So I am assuming it's taking the entire space.
I think it's your last FrameLayout where is height is match_parent and is overlapping everything.
If it's not this layout try to replace others layout by wrap_content or when your run your app, you have "layout inspector" in Android Studio and you can find your error.
Remove this from your Recyclerview: android:layout_marginTop="700dp"".
It has set the top margin 700dp which makes it go out of the screen.
Edit
I figured out my issue. My recycler view items were not displaying because of how my data was structured in firebase. Thank you everyone for your help.
i have been trying to create a QR Code generator that generates the QR Code on a separate activity on button click. Below is my code but it crushes on button click. Where did i go wrong?
First class is MainActivity.class:
package com.example.profmox.myapplication;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.journeyapps.barcodescanner.BarcodeEncoder;
public class MainActivity extends AppCompatActivity {
TextView tx1;
Button btn1, btn2;
EditText edt1,edt2;
CheckBox ch;
String text2qr;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt1 = (EditText)findViewById(R.id.edit1);
edt2 = (EditText)findViewById(R.id.edit2);
btn1 = (Button)findViewById(R.id.login);
btn2 = (Button)findViewById(R.id.signup);
ch = (CheckBox)findViewById(R.id.check);
btn1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.v("EditText", edt1.getText().toString());
Log.v("EditText", edt2.getText().toString());
// text2qr = edt1.getText().toString().trim();
// MultiFormatWriter mfw = new MultiFormatWriter();
// try{
// BitMatrix btm = mfw.encode(text2qr, BarcodeFormat.QR_CODE,250,250);
// BarcodeEncoder ben = new BarcodeEncoder();
// Bitmap bmap = ben.createBitmap(btm);
// UserScreen.qr.setImageBitmap(bmap);
// }catch (WriterException e){
// e.printStackTrace();
// }
startActivity(new Intent(MainActivity.this, UserScreen.class));
}
});
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, SignUp.class));
}
});
}
}
The layout file for the MainActivity class:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
android:background="#drawable/art_background"
tools:context="com.example.profmox.myapplication.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="300dp"
android:layout_height="230dp"
android:layout_gravity="center_horizontal"
android:padding="16dp"
android:layout_marginTop="20dp"
android:src="#mipmap/logo"/>
<EditText
android:id="#+id/edit1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textEmailAddress"
android:ems="10"
android:background="#android:color/transparent"
android:drawablePadding="12dp"
android:padding="8dp"
android:hint="Username"
android:textColorHint="#fff"
android:maxLines="1"
android:drawableLeft="#drawable/girl"
android:layout_marginTop="70dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#F2CC8F"/>
<EditText
android:id="#+id/edit2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textPassword"
android:ems="10"
android:background="#android:color/transparent"
android:drawablePadding="12dp"
android:padding="8dp"
android:hint="Password"
android:textColorHint="#fff"
android:maxLines="1"
android:layout_marginTop="4dp"
/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#F2CC8F"/>
<CheckBox
android:id="#+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textColor="#fff"
android:text="Remember Me"
android:padding="9dp"
/>
<Button
android:id="#+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/login_art"
android:text="Login"
android:textColor="#3D405B"
android:textAllCaps="false"
android:padding="16dp"
android:clickable="true"
style="#style/Base.TextAppearance.AppCompat.Body1"
android:layout_marginTop="23dp"
android:textSize="18sp"/>
<Button
android:id="#+id/signup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/signuo_art"
android:text="Sign up"
android:textColor="#fff"
style="#style/Base.TextAppearance.AppCompat.Body1"
android:textAllCaps="false"
android:textSize="18sp"
android:layout_marginTop="16dp"
android:clickable="true"
android:padding="16dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Forgot your password?"
android:clickable="true"
style="#style/Base.TextAppearance.AppCompat.Body2"
android:padding="16dp"
android:layout_marginBottom="12dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
The UserScreen.class is where i want to generate the QR Code in:
package com.example.profmox.myapplication;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
public class UserScreen extends AppCompatActivity {
static ImageView qr;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_screen);
qr = (ImageView)findViewById(R.id.qrCode);
}
}
The layout file for the UserScreen.class:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/art_background"
android:paddingLeft="18dp"
android:paddingRight="18dp"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.profmox.myapplication.UserScreen">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/qrCode"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
I have written a sign-In xml page and I am checking the eligibility of the user to login through Firebase database. Now after entering the username and password , I am clicking on the "Sign-In" button. It is taking few seconds to load the Home page after this. So I want to display a Progress Bar which revolves during that time and stops on opening the Home page.
My layout page for sing-In is:
<?xml version="1.0" encoding="utf-8"?>
<ProgressBar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.hsports.bandpop.MainActivity"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/title"
android:text="WEDDING PLANNER"
android:gravity="center"
android:textSize="50dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:paddingTop="100dp"
>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Layout_username"
android:hint="Username"
>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/username"
android:gravity="center"
/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Layout_password"
android:hint="Password"
>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/password"
android:gravity="center"
android:inputType="textPassword"
/>
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="50dp"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SIGN IN"
android:onClick="checkSignIn"
android:gravity="center"
android:id="#+id/SignInButton"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="REGISTER"
android:onClick="registerForm"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ProgressBar>
And the code as a fragment on clicking the "SignIn" button is:
package com.example.hsports.weddingplanner.Fragments;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.example.hsports.weddingplanner.Activities.FrontPage;
import com.example.hsports.weddingplanner.Activities.WeddingPlanningUsers;
import com.example.hsports.weddingplanner.R;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
/**
* Created by I324671 on 11/28/2016.
*/
public class SignIn extends Fragment {
SharedPreferences sharedPreferences;
String MyPreferences="loginUserInfo";
ProgressBar afterSignIn;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
final View view=inflater.inflate(R.layout.activity_login_page, container, false);
afterSignIn=(ProgressBar)view.findViewById(R.id.loadingSignIn);
Button checkSignIn=(Button)view.findViewById(R.id.SignInButton);
checkSignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
afterSignIn.setVisibility(view.VISIBLE);
final String username = ((TextView) (view.findViewById(R.id.username))).getText().toString();
final String password = ((TextView) (view.findViewById(R.id.password))).getText().toString();
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference reference = database.getReference("Users");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChildren()) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
String usernameFromDB=child.getKey().toString();
String passwordFromDB=child.getValue().toString();
if(username.equals(usernameFromDB)&& password.equals(passwordFromDB))
{
sharedPreferences=getContext().getSharedPreferences(MyPreferences, Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("Username",username);
editor.putString("Password", password);
editor.commit();
afterSignIn.setVisibility(view.GONE);
Intent transferToHome=new Intent(getContext(), FrontPage.class);
startActivity(transferToHome);
break;
}
}
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.d("The read failed", databaseError.getDetails());
}
});
}
});
return view;
}
}
The error which I ma getting on executing this is :
"Binary XML file android.widget.ProgressBar cannot be cast to android.view.ViewGroup".
How can I resolve this.
The Problem is that you
Have to close top tag inside XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ProgressBar
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
/>
And:
Use
</LinearLayout>
</ScrollView>
</LinearLayout>
You can have only one root of your layout file. Here you have two. namely ProgessBar and ScrollView. Try encapsulating them in FrameLayout and everything will be alright.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ProgressBar
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
>
<ScrollView
...
</ScrollView>
</FrameLayout>
edit -->
for making progress bar center wise, change
<ProgressBar
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:id="#+id/loadingSignIn"
android:indeterminate="true"
android:visibility="invisible"
/>
and handle invisibility / visibility. :)
I'm trying to make a Toast message whenever I click an item from the list, For some reason when I click the item nothing happens,
I hope you can help me, thanks.
ProductList.java
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.util.SparseBooleanArray;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.support.v4.app.FragmentManager;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ProductList extends AppCompatActivity {
private List<myProductsView> myProducts_types = new ArrayList<myProductsView>();
ArrayAdapter<myProductsView> adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pop_productlist);
//Button btnDel = (Button) findViewById(R.id.btnDel);
//adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice,list);
populateProductsList();
populateListView();
}
private void populateProductsList() {
myProducts_types.add(new myProductsView("aaa", "aaa", 1111, 12.90, R.drawable.cereal, 1));
myProducts_types.add(new myProductsView("aaa", "aaaaaa ", 1112, 10.90, R.drawable.cereal, 2));
myProducts_types.add(new myProductsView("aaa", "aaa", 1112, 30.00, R.drawable.cereal, 1));
myProducts_types.add(new myProductsView("aaa", "aaa", 1112, 20.00, R.drawable.cereal, 3));
}
private void populateListView() {
adapter = new MyListAdapter();
ListView list = (ListView) findViewById(R.id.product_list);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("BLALBALBLALBLABLAL");
Toast.makeText(ProductList.this, "BLA", Toast.LENGTH_SHORT);
}
});
}
public void StartCalck(View view){
Intent intent = new Intent(ProductList.this, SplitBuying.class);
startActivity(intent);
}
public class MyListAdapter extends ArrayAdapter<myProductsView>{
public MyListAdapter(){
super(ProductList.this, R.layout.pop_productlist, myProducts_types);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
//make sure we have a view to work with(may have been given null
View itemView = convertView;
if(itemView == null){
itemView = getLayoutInflater().inflate(R.layout.product_item_view, parent, false);
}
//we need to populate the list
//find the product to work with
myProductsView currentProduct = myProducts_types.get(position);
//fill the view
CheckBox checkBox = (CheckBox)itemView.findViewById(R.id.product_checkBox);
checkBox.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(ProductList.this,"BLA",Toast.LENGTH_SHORT);
}
});
TextView productname = (TextView) itemView.findViewById(R.id.product_name);
productname.setText(currentProduct.getProductName());
EditText quantity = (EditText)itemView.findViewById(R.id.edit_text);
quantity.setText(String.valueOf(currentProduct.getQuantity()));
return itemView;
}
}
}
product_item_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="7dp"
android:layout_weight="1">
<Button
android:id="#+id/btn_minus"
android:layout_width="35dp"
android:layout_height="40dp"
android:text="-" />
<EditText
android:id="#+id/edit_text"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:inputType="number"
android:gravity="center"
android:focusable="false"
android:text="0" />
<Button
android:id="#+id/btn_plus"
android:layout_width="35dp"
android:layout_height="40dp"
android:text="+" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Text"
android:textSize="15dp"
android:textIsSelectable="true"
android:gravity="center"
android:id="#+id/product_name"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/product_checkBox"
android:layout_toStartOf="#+id/product_checkBox" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="5dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/product_checkBox" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
pop_productlist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="#drawable/ightwall"
android:id="#+id/drawerlayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="הרשימה שלי"
android:textAlignment="center"
android:textSize="30dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="#+id/product_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:choiceMode="multipleChoice"
android:layout_below="#+id/ChooseStore"
>
</ListView>
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/CalckButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calckButton"
android:onClick="StartCalck"
android:layout_gravity="center" />
<Button
android:id="#+id/btnDel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="#string/lblBtnDel"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#D5D4D4"
android:layout_gravity="bottom">
<ImageView
android:id="#+id/mylist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/createlist_mylist"
android:adjustViewBounds="true"
android:maxHeight="90dp"
android:maxWidth="90dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<ImageView
android:id="#+id/freeadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/createlist_freetext"
android:adjustViewBounds="true"
android:maxHeight="90dp"
android:maxWidth="90dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<ImageView
android:id="#+id/favproductadd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/createlist_favproduct"
android:adjustViewBounds="true"
android:maxHeight="90dp"
android:maxWidth="90dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
</LinearLayout>
You have to call .show() on your toast.
change
Toast.makeText(ProductList.this, "BLA", Toast.LENGTH_SHORT);
to
Toast.makeText(ProductList.this, "BLA", Toast.LENGTH_SHORT).show();
In the following code Sliding drawer menu bar is coming but when i click on the menu items nothing happens.I am looking forward to open the sliding drawer on button click of the buttonmenu.I dont know how to open a sliding drawer on button click.When i click on the drawer it disappers to the left hand side.I want to write the code like this if i click on menu item (home) it should open Mainactivity.class.I have not written the code for that.
package com.bar.start;
import com.bar.barapp.R;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button loc,buttonmenu;
String[] menu;
DrawerLayout dLayout;
ListView dList;
ArrayAdapter<String> adapter;
#Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.homescreen);
// getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar);
menu = new String[]{"Home","Android","Windows","Linux","Raspberry Pi","WordPress","Videos","Contact Us"};
dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
dList = (ListView) findViewById(R.id.left_drawer);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,menu);
dList.setAdapter(adapter);
dList.setSelector(android.R.color.holo_blue_dark);
dList.setOnItemClickListener(new OnItemClickListener(){
#Override
public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
dLayout.closeDrawers();
Bundle args = new Bundle();
args.putString("Menu", menu[position]);
Fragment detail = new Menu_view();
detail.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, detail).commit();
}
});
loc=(Button)findViewById(R.id.location);
loc.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent in =new Intent(MainActivity.this,LocationActivity.class);
startActivity(in);
}
});
buttonmenu=(Button)findViewById(R.id.menubutton);
buttonmenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "hello", Toast.LENGTH_LONG).show();
}
});
}
}
homescreen.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:background="#800000"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/startupscreen">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/menulayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:paddingTop="30dp"
android:orientation="horizontal">
<Button
android:id="#+id/menubutton"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.3"
android:text="#string/menu"
/>
<TextView
android:layout_weight="0.2"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
<TextView
android:layout_weight="0.2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/search"
android:textSize="14sp"
android:textColor="#color/black"/>
<EditText
android:layout_weight="0.3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:focusable="false"
android:focusableInTouchMode="true"/>
</LinearLayout>
<ExpandableListView
android:layout_below="#+id/menulayout"
android:id="#+id/searchres"
android:layout_width="fill_parent"
android:layout_height="350dp"
android:clipChildren="true"
android:groupIndicator="#null"
android:background="#color/gray"
/>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="match_parent"
android:layout_height="50dp"
android:weightSum="1.5"
android:orientation="horizontal"
android:layout_below="#+id/searchres">
<Button
android:id="#+id/location"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.5"
android:text="#string/location"
android:background="#drawable/btn_image"
/>
<Button
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.5"
android:visibility="invisible"
/>
<Button
android:id="#+id/barype"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.5"
android:text="#string/bartype"
android:background="#drawable/btn_image"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#+id/buttons">
<Button
android:id="#+id/joggle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="#drawable/btn_image"
android:text="#string/joggle"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
Menuview.java
public class Menu_view extends Fragment{
TextView text;
#Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle args) {
View view = inflater.inflate(R.layout.menu_detail, container, false);
String menu = getArguments().getString("Menu");
text= (TextView) view.findViewById(R.id.detail);
text.setText(menu);
return view;
}
}
menu_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center"
android:background="#5ba4e5"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40px"
android:textColor="#000000"
android:layout_gravity="center"
android:id="#+id/detail"/>
</LinearLayout>