Skip to content

Commit

Permalink
fragment item click
Browse files Browse the repository at this point in the history
raju122214 committed Sep 3, 2019
1 parent f3c2f72 commit 4724cf9
Showing 7 changed files with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
public class SubCategoryAdapter extends RecyclerView.Adapter<SubCategoryAdapter.MyViewHolder> {
List<CategoryByProductIdModel.Child> categoryByProductIdModels;
Context context;
private onClick listener;

public SubCategoryAdapter(Context context, List<CategoryByProductIdModel.Child> categoryByProductIdModels) {
this.context = context;
this.categoryByProductIdModels = categoryByProductIdModels;
@@ -40,11 +42,15 @@ public void onBindViewHolder(MyViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, categoryByProductIdModels.get(position).getParentId()+ " is clicked hhhh", Toast.LENGTH_SHORT).show();
// Toast.makeText(context, categoryByProductIdModels.get(position).getParentId()+ " is clicked hhhh", Toast.LENGTH_SHORT).show();
if (listener != null) //call interface
listener.clickListener(categoryByProductIdModels.get(position));
}
});
}

public void setListener(onClick listener) {
this.listener = listener;
}
@Override
public int getItemCount() {
return categoryByProductIdModels.size();
@@ -56,4 +62,8 @@ public MyViewHolder(View itemView) {
name = (TextView) itemView.findViewById(R.id.name);
}
}

public interface onClick {
void clickListener(CategoryByProductIdModel.Child child);
}
}
Original file line number Diff line number Diff line change
@@ -136,8 +136,8 @@ public void onItemClick(AllServiceModel item) {
Toast.makeText(getActivity(), item.getName() + " is clicked ker", Toast.LENGTH_SHORT).show();
Bundle bundle = new Bundle();
bundle.putString("productId",item.getProductId());
// Fragment fragment = new SubCategoryFragment();
Fragment fragment = new SubCategoryPriceFragment();
Fragment fragment = new SubCategoryFragment();
// Fragment fragment = new SubCategoryPriceFragment();
fragment.setArguments(bundle);
loadFragment(fragment);
getAddress();
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -31,7 +33,7 @@ public class SubCategoryFragment extends Fragment implements CategoryByProductId
private Context context;
private Activity activity;
private RecyclerView recyclerView;

private SubCategoryAdapter subCategoryAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@@ -50,6 +52,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,


recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
DividerItemDecoration.VERTICAL));
// setAdapter();


@@ -65,10 +69,27 @@ public void onAttach(Context context) {
void setAdapter(List<CategoryByProductIdModel.Child> categoryByProductIdModels){
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(linearLayoutManager);
SubCategoryAdapter subCategoryAdapter = new SubCategoryAdapter(getActivity(), categoryByProductIdModels);
subCategoryAdapter = new SubCategoryAdapter(getActivity(), categoryByProductIdModels);
recyclerView.setAdapter(subCategoryAdapter);
subCategoryAdapter.setListener(new SubCategoryAdapter.onClick() {
@Override
public void clickListener(CategoryByProductIdModel.Child child) {

Toast.makeText(context, child.getParentId()+ " is clicked aa gaya", Toast.LENGTH_SHORT).show();
Bundle bundle = new Bundle();
bundle.putInt("ParentId",child.getParentId());
Fragment fragment = new SubCategoryPriceFragment();
fragment.setArguments(bundle);
loadFragment(fragment);
}
});
}
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.home_fragment_container, fragment);
transaction.commit();
}


@Override
public void onFetchCategoryByProductIdeSuccess(List<CategoryByProductIdModel> categoryByProductIdModels) {
@@ -83,4 +104,6 @@ public void onFetchCategoryByProductIdeSuccess(List<CategoryByProductIdModel> ca
public void onFetchCategoryByProductIdFailure(String msg) {

}


}
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@@ -40,16 +41,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle bundle = getArguments();

if(bundle != null){
String productId = bundle.getString("productId");
productId = "20";
controller.fetchCategoryById(context,this,""+productId);
int ParentId = bundle.getInt("ParentId");
ParentId = 20;
controller.fetchCategoryById(context,this,""+ParentId);
}




recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);

recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
DividerItemDecoration.VERTICAL));
return view;
}

Binary file added app/src/main/res/drawable/control.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 13 additions & 17 deletions app/src/main/res/layout/fragment_subcategeryprice.xml
Original file line number Diff line number Diff line change
@@ -18,38 +18,34 @@

<View
android:id="@+id/view_first"
android:layout_below="@+id/txt_header"
android:layout_width="match_parent"
android:layout_height=".5dp"
android:layout_below="@+id/txt_header"
android:background="@android:color/holo_green_light" />


<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_below="@+id/view_first"
<RelativeLayout
android:id="@+id/recyclerViewRout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


<View
android:layout_below="@+id/recyclerView"
android:id="@+id/view_three"
android:layout_width="match_parent"
android:layout_height=".5dp"
android:layout_above="@+id/btn_next"
android:background="@android:color/holo_green_light" />
android:layout_below="@+id/view_first">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</RelativeLayout>


<Button
android:id="@+id/btn_next"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="8dp"
android:background="@android:color/black"
android:text="Next"
android:textColor="@android:color/white"
android:textAllCaps="false"/>
android:textAllCaps="false"
android:textColor="@android:color/white" />
</RelativeLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/subcatageryitem.xml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="6dp"
android:src="@drawable/ic_launcher_background"/>
android:src="@drawable/control"/>

<ImageView
android:src="@drawable/round"

0 comments on commit 4724cf9

Please sign in to comment.