Это класс модели
public class AmountCartModel {
private String testName;
private String testPrice;
public AmountCartModel() {
this.testName = testName;
this.testPrice = testPrice;
}
public String getTestName() {
return testName;
}
public void setTestName(String testName) {
this.testName = testName;
}
public String getTestPrice() {
return testPrice;
}
public void setTestPrice(String testPrice) {
this.testPrice = testPrice;
}
}
Это моя деятельность
public class AmountCartActivity extends AppCompatActivity
private RecyclerView recyclerView;
List<AmountCartModel> mydataList ;
private MyAdapter madapter;
Bundle extras ;
String testName="";
String testPrice="";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_amount_cart);
mydataList = new ArrayList<>();
/*
* Getting Values From BUNDLE
* */
extras = getIntent().getExtras();
if (extras != null) {
testName = extras.getString("test_name");
testPrice = extras.getString("test_price");
//Just add your data in list
AmountCartModel mydata = new AmountCartModel(); // object of Model Class
mydata.setTestName(testName );
mydata.setTestPrice(testPrice);
mydataList.add(mydata);
}
madapter=new MyAdapter(mydataList);
madapter.setMyDataList(mydataList);
recyclerView = (RecyclerView)findViewById(R.id.recyler_amount_cart);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(madapter);
}
Это мой адаптер для утилизации
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private Context context;
private List<AmountCartModel> myDataList;
public MyAdapter(Context context) {
this.context = context;
myDataList = new ArrayList<>();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Replace with your layout
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.amount_cart_row, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// Set Your Data here to yout Layout Components..
// to get Amount
holder.testName.setText(myDataList.get(position).getTestName());
holder.testPrice.setText(myDataList.get(position).getTestPrice());
}
@Override
public int getItemCount() {
return myDataList.size();
}
public void setMyDataList(List<AmountCartModel> myDataList) {
// getting list from Fragment.
this.myDataList = myDataList;
notifyDataSetChanged();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView testName,testPrice;
public ViewHolder(View itemView) {
super(itemView);
// itemView.findViewById
testName=itemView.findViewById(R.id.test_name_one);
testPrice=itemView.findViewById(R.id.price_name);
}
}
}
}
Logcat
E / AndroidRuntime: ИСКЛЮЧИТЕЛЬНОЕ ИСКЛЮЧЕНИЕ: основной процесс: com.snpinfotech.snp.aoplapp, PID: 11874 java.lang.NullPointerException в com.snpinfotech.snp.aoplapp.aopl.amountCartContent.AmountCartActivity $ MyAdapter.onBind) на com.snpinfotech.snp.aoplapp.aopl.amountCartContent.AmountCartActivity $ MyAdapter.onBindViewHolder (AmountCartActivity.java:343) на android.support.v7.widget.RecyclerView $ Adapter.onBindViewHolder (android6).support.v7.widget.RecyclerView $ Adapter.bindViewHolder (RecyclerView.java:6515) в android.support.v7.widget.RecyclerView $ Recycler.tryBindViewHolderByDeadline (RecyclerView.java:5458) в android.support.Recycler $Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:5724) в android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition (RecyclerView.java:5563) в android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition (RecyclerView.java:5559) в android.support.v7.widget.LinearLayoutManager $ LayoutState.next (LinearLayoutManager.java:2229 at).support.v7.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1556) при android.support.v7.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1516) в android.support.v7.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java: 608) в android.support.v7.widget.RecyclerView.dispatchLayoutStep2 (RecyclerView.java:3693) в android.support.v7.widget.RecyclerView.dispatchLayout (RecyclerView.java:3410) в android.support.7widget.RecyclerView.onLayout (RecyclerView.java:3962) на android.view.View.layout (View.java:15125) на android.view.ViewGroup.layout (ViewGroup.java:4862) на android.widget.RelativeLayout.onLayout(RelativeLayout.java:1160) на android.view.View.layout (View.java:15125) на android.view.ViewGroup.layout (ViewGroup.java:4862) на android.widget.RelativeLayout.onLayout (RelativeLayout.java:1160) в android.view.View.layout (View.java:15125) в android.view.ViewGroup.layout (ViewGroup.java:4862) в android.widget.FrameLayout.layoutChildren (FrameLayout.java:515) в android.widget.FrameLayout.onLayout (FrameLayout.java:450) в android.view.View.layout (View.java:15125) в android.view.ViewGroup.layout (ViewGroup.java)4862.view.View.layout (View.java:15125) на android.view.ViewGroup.layout (ViewGroup.java:4862) на android.widget.FrameLayout.layoutChildren (FrameLayout.java:515) на android.widget.FrameLayout.onLayout (FrameLayout.java:450) в android.view.View.layout (View.java:15125) в android.view.ViewGroup.layout (ViewGroup.java:4862) в android.widget.LinearLayout.setChildFrame (LinearLayout.java): 1888) на android.widget.LinearLayout.layoutVertical (LinearLayout.java:1742)на android.widget.LinearLayout.onLayout (LinearLayout.java:1651) на android.view.View.layout (View.java:15125) на android.view.ViewGroup.layout (ViewGroup.java:4862) на android.widget.FrameLayout.layoutChildren (FrameLayout.java:515) в android.widget.FrameLayout.onLayout (FrameLayout.java:450) в android.view.View.layout (View.java:15125) в android.view.ViewGroup.layout (ViewGroup).java: 4862) в android.view.ViewRootImpl.performLayout (ViewRootImpl.java:2317) в android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2023) в android.view.ViewRootImpl.doTrajal11в android.view.ViewRootImpl $ TraversalRunnable.run (ViewRootImpl.java:6223) в android.view.Choreographer $ CallbackRecord.run (хореограф.java:788) в android.view.Choreographer.doCallbacks в 59android.view.Choreographer.doFrame (Choreographer.java:560) в android.view.Choreographer $ FrameDisplayEventReceiver.run (Choreographer.java:774) в android.os.Handler.handleCallback (Handler.ja)va: 808) на android.os.Handler.dispatchMessage (Handler.java:103) на android.os.Looper.loop (Looper.java:193) на android.
Здесь я получаю значения из предыдущегоПредставление Activity Recycler И я пытаюсь отобразить его с помощью Bundle в этом упражнении.
Проблема в том, что когда я делаю это с помощью этого подхода, действие не показывает мне ничего, и я получаю значения в своем комплекте, в чем проблема, которой я не являюсьполучать это.Любая помощь будет принята с благодарностью.спасибо