0

I am using a Recyclerview inside the coordinator layout.In the Main.Xml i have a save button and Edit Text field. So On click to save Button i need to pass the edit text value to next Xml that have RecyclerView. But run time error occurs. What is really happening to this code?

MainActivity:

public class MainActivity extends AppCompatActivity implements RecyclerViewAdapter.OnItemClickListener {
EditText textIn,txtHeading;
Button buttonAdd,btnsave;
LinearLayout container;


private RecyclerView myRecyclerView;
private LinearLayoutManager linearLayoutManager;
private RecyclerViewAdapter myRecyclerViewAdapter;
private RecyclerView.LayoutManager recyclermanager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    myRecyclerView = (RecyclerView)findViewById(R.id.recyclerView_builderxml);

    linearLayoutManager =
            new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);

    myRecyclerViewAdapter = new RecyclerViewAdapter(this);
    myRecyclerViewAdapter.setOnItemClickListener(this);

    myRecyclerView.setAdapter(myRecyclerViewAdapter);
    myRecyclerView.setLayoutManager(linearLayoutManager);

    txtHeading = (EditText)findViewById(R.id.heading);

    btnsave =(Button) findViewById(R.id.btn_save);
    btnsave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String newName = txtHeading.getText().toString();
            Intent intent = new Intent(getApplicationContext(),BuilderPage.class);
            myRecyclerViewAdapter.add(0,newName);
            startActivity(intent);
            Toast.makeText(MainActivity.this,"You added" +newName.toUpperCase()+ "in your view",Toast.LENGTH_LONG).show();
        }
    });
}
 @Override
    public void onItemClick(RecyclerViewAdapter.ItemHolder item, int position) {
    }
}

BuilderPage

/*
 * Created by niroj on 8/29/16.
 */


public class BuilderPage extends AppCompatActivity {

    @BindView(R.id.edittxtsurvey)
    EditText editTxtsurveyname;

    @BindView(R.id.toolbar_builderxml)
    Toolbar toolbar1;

    @BindView(R.id.recyclerView_builderxml)
    RecyclerView recyclerView_Builder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.builder_layout);
        ButterKnife.bind(this);
        setSupportActionBar(toolbar1);
        getSupportActionBar().setDisplayShowTitleEnabled(false);

        // display menu incons from menu_main XML
  }

}

And My Builder.XML

<?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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView_builderxml"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.AppBarLayout
      android:id="@+id/appBarLayout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

      <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_builderxml"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways">

      </android.support.v7.widget.Toolbar>
    </android.support.design.widget.AppBarLayout>
  </android.support.design.widget.CoordinatorLayout>

This is my adapterclass for recycler

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ItemHolder> {

    private List<String> HeadingName;
    private OnItemClickListener onItemClickListener;
    private LayoutInflater layoutInflater;

    public RecyclerViewAdapter(Context context){
        layoutInflater = LayoutInflater.from(context);
        HeadingName = new ArrayList<String>();
    }

    @Override
    public RecyclerViewAdapter.ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.list_item, parent, false);
        return new ItemHolder(itemView, this);
    }

    @Override
    public void onBindViewHolder(RecyclerViewAdapter.ItemHolder holder, int position) {
        holder.setItemName(HeadingName.get(position));

    }

    @Override
    public int getItemCount() {
        return HeadingName.size();
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        onItemClickListener = listener;
    }

    public OnItemClickListener getOnItemClickListener(){
        return onItemClickListener;
    }

    public interface OnItemClickListener{
        public void onItemClick(ItemHolder item, int position);
    }

    public void add(int location, String iName){
        HeadingName.add(location, iName);
        notifyItemInserted(location);
    }


    public static class ItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener{

        private RecyclerViewAdapter parent;
        TextView textHeadingname;

        public ItemHolder(View itemView, RecyclerViewAdapter parent) {
            super(itemView);
            itemView.setOnClickListener(this);
            this.parent = parent;
            textHeadingname = (TextView) itemView.findViewById(R.id.title_name);
        }

        public void setItemName(CharSequence name){
            textHeadingname.setText(name);
        }

        public CharSequence getItemName(){
            return textHeadingname.getText();
        }

        @Override
        public void onClick(View v) {
            final OnItemClickListener listener = parent.getOnItemClickListener();
            if(listener != null){
                listener.onItemClick(this, getPosition());
            }
        }
    }
}

Error Log

This is my manifest

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <!--android:theme="@style/Theme.AppCompat.Light"--> >
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"
                android:theme ="@android:style/Theme.Black.NoTitleBar.Fullscreen"/>

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Niroj
  • 1,114
  • 6
  • 29

1 Answers1

0

You haven't added the activity tag for your Builder page in your manifest. In your manifest add the activity tag for your Builder Page like this

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<!--android:theme="@style/Theme.AppCompat.Light"--> >
<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"
            android:theme ="@android:style/Theme.Black.NoTitleBar.Fullscreen"/>

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

<!--Activity Tag for your BuilderPage-->
<activity android:name=".BuilderPage">
    </activity>

</application>
Akhil Soman
  • 2,077
  • 2
  • 17
  • 30