Recycler View is Not Displaying - android

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.

Related

White space between each item in recycler view

I'm using Firebase Recycler in my app and I implemented the code in my fragment. The data loads fine but when I scroll to end of list the items gets white spaces between each and that spaces clears only when changed from one activity to other.
My XML Code:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="55dp">
<androidx.appcompat.widget.Toolbar
android:id="#+id/home_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary">
<TextView
android:id="#+id/map_view"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:drawableStart="#drawable/ic_location_on_black_24dp"
android:drawablePadding="10dp"
android:ellipsize="end"
android:fontFamily="#font/roboto_medium"
android:gravity="center"
android:maxLines="1"
android:padding="5dp"
android:text="#string/text1" />
</androidx.appcompat.widget.Toolbar>
<androidx.cardview.widget.CardView
app:cardCornerRadius="10dp"
android:layout_margin="14dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.smarteist.autoimageslider.SliderView
android:id="#+id/imageSlider"
android:layout_width="match_parent"
android:layout_height="200dp"
app:sliderAnimationDuration="5000"
app:sliderAutoCycleEnabled="true"
app:sliderIndicatorAnimationDuration="5000"
app:sliderIndicatorGravity="center_horizontal|bottom"
app:sliderIndicatorMargin="15dp"
app:sliderIndicatorOrientation="horizontal"
app:sliderIndicatorPadding="3dp"
app:sliderIndicatorRadius="1dp"
app:sliderIndicatorSelectedColor="#5A5A5A"
app:sliderIndicatorUnselectedColor="#FFF"
app:sliderScrollTimeInSec="3"
app:sliderStartAutoCycle="true" />
</androidx.cardview.widget.CardView>
<RadioGroup
android:id="#+id/layout_change_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<RadioButton
android:id="#+id/btn_for_list1"
android:layout_width="150dp"
android:gravity="center"
android:layout_height="30dp"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:checked="true"
android:text="Home Services"
android:textColor="#color/radio_flat_text_selector" />
<RadioButton
android:id="#+id/btn_for_list2"
android:gravity="center"
android:layout_width="150dp"
android:layout_height="30dp"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:text="Home Improvements"
android:textColor="#color/radio_flat_text_selector" />
</RadioGroup>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_list1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="15dp"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/main_list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="15dp"/>
</RelativeLayout>
</LinearLayout>
My Adapter Code:
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.coderedinnovations.allioservices.R;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
public class MainList1_Adapter extends FirebaseRecyclerAdapter<MainList1, MainList1_Adapter.MainList1_Holder> {
public MainList1_Adapter(#NonNull FirebaseRecyclerOptions<MainList1> options) {
super(options);
}
#Override
protected void onBindViewHolder(#NonNull MainList1_Holder holder, int position, #NonNull MainList1 model) {
holder.heading_view.setText(model.getTitle());
holder.desc_view.setText(model.getDescription());
holder.offer_view.setText(model.getOffer());
Glide.with(holder.image_view.getContext())
.load(model.getImageLink())
.into(holder.image_view);
}
#NonNull
#Override
public MainList1_Holder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.main_item_card, parent, false);
return new MainList1_Holder(view);
}
class MainList1_Holder extends RecyclerView.ViewHolder{
TextView heading_view, desc_view, offer_view;
ImageView image_view;
public MainList1_Holder(#NonNull View itemView) {
super(itemView);
heading_view = itemView.findViewById(R.id.item_heading);
desc_view = itemView.findViewById(R.id.item_description);
offer_view = itemView.findViewById(R.id.item_offer);
image_view = itemView.findViewById(R.id.item_image);
}
}
}
Watch this video that will clear explain my problem.
Video Link
Thanks for everyone who tried to answer my question. I just made a small mistake which gave the white spaces between each item.
In the Parent layout of item. I added
android:layout_height:"match_parent"
instead of wrap_content and that made the error.

Generating QR Code on different activity in android

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>

RecyclerView click on item, take some data then go to another activity

I want to take the reference when i click on an item in this recyclerview then go to another activity with this reference there is override functions in listview but recylclerview didn't have the same function
card.xml :
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="wrap_content"
android:layout_height="119dp"
android:layout_gravity="center"
android:elevation="3dp"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="1dp"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="112dp">
<TextView
android:text="ID Article : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_idArticle1"
android:textStyle="normal|bold"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#android:color/black" />
<TextView
android:text="Reference : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_reference1"
android:textStyle="normal|bold"
android:layout_above="#+id/txt_des"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="5dp"
android:textColor="#android:color/background_dark" />
<TextView
android:text="Prix : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_des1"
android:textStyle="normal|bold"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="-51dp"
android:layout_below="#+id/txt_des"
android:textColor="#android:color/background_dark" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_des"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/txt_prix1"
android:layout_toEndOf="#+id/txt_prix1" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_prix"
android:layout_alignBaseline="#+id/txt_des1"
android:layout_alignBottom="#+id/txt_des1"
android:layout_toRightOf="#+id/txt_des1"
android:layout_toEndOf="#+id/txt_des1" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_idArticle"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/txt_idArticle1"
android:layout_toEndOf="#+id/txt_idArticle1" />
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txt_reference"
android:layout_alignBaseline="#+id/txt_reference1"
android:layout_alignBottom="#+id/txt_reference1"
android:layout_toRightOf="#+id/txt_reference1"
android:layout_toEndOf="#+id/txt_reference1" />
<TextView
android:text="Designation : "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt_prix1"
android:textStyle="normal|bold"
android:textColor="#android:color/black"
android:layout_below="#+id/txt_reference1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="5dp"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.CardView> </LinearLayout>
avticity_recherche_art.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:article_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/activity_recherche_art"
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.bacha.pfe.activity.recherche_art">
<TextView
android:text="Recherche Article :"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:textSize="24sp"
android:textStyle="normal|bold"
android:textAlignment="center"
android:textColor="?attr/colorPrimary"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:text="rechercher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnrechArt"
android:layout_marginRight="20dp"
android:layout_marginEnd="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/eTextRechArt" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="#+id/eTextRechArt"
android:layout_below="#+id/textView"
android:layout_toLeftOf="#+id/btnrechArt"
android:layout_toStartOf="#+id/btnrechArt" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
article_view:cardUseCompatPadding="true"
article_view:cardElevation="5dp"
article_view:cardCornerRadius="5dp"
android:scrollbars="vertical"
android:layout_marginTop="18dp"
android:layout_below="#+id/btnrechArt"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
recherche_art.java:
package com.example.bacha.pfe.activity;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.bacha.pfe.R;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class recherche_art extends AppCompatActivity {
private RecyclerView recyclerView ;
private GridLayoutManager gridLayoutManager;
private ArticleAdapter adapter ;
private List<Article> data_list ;
private String recherche_article;
private Button btnrechArt ;
private EditText arech;
int d=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recherche_art);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
btnrechArt = (Button) findViewById(R.id.btnrechArt);
btnrechArt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
arech= (EditText) findViewById(R.id.eTextRechArt);
data_list = new ArrayList<>();
recherche_article=arech.getText().toString();
load_article_from_server(0);
gridLayoutManager = new GridLayoutManager(recherche_art.this,1);
recyclerView.setLayoutManager(gridLayoutManager);
adapter = new ArticleAdapter(recherche_art.this,data_list);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if(gridLayoutManager.findLastCompletelyVisibleItemPosition() == data_list.size()-1){
d=data_list.size();
Log.d("PFE", String.valueOf(d));
load_article_from_server(d);
}
}
});
}
});
}
private void load_article_from_server(final int id) {
AsyncTask<Integer, Void, Void> task = new AsyncTask<Integer,Void, Void>() {
#Override
protected Void doInBackground(Integer... Params) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("http://10.0.2.2/slim/article/"+recherche_article+"/"+id).build();
try {
Response response = client.newCall(request).execute();
JSONArray array = new JSONArray(response.body().string());
for(int i=0;i<array.length();i++){
JSONObject object = array.getJSONObject(i);
Article data = new Article(/*dd,*/object.getString("id_Article"),object.getString("Reference"),object.getString("Designation"),object.getString("PVTTC"));
data_list.add(data);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
System.out.print("End of content");
}
return null ;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
adapter.notifyDataSetChanged();
}
};
task.execute(id);
}
}
You have to implement a listener in the holder that you are using in the ArticleAdapter.
Look this: RecyclerView onClick

Adding Scrollview covers up toolbar

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)

OnItemClickListener doesn't work , OnItemClick is not called

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();

Categories

Resources