intent.getStringExtra

1

I'm trying to bring a few things from a recyclerview and the case is that if I can the name but neither the category nor the image. How can I get it?

public class Platos_Adapter extends RecyclerView.Adapter<Platos_Adapter.ViewHolder> {

    private ImageLoader imageLoader;
    private Context context;

    List<Estadisticas> estadisticas;

    public Platos_Adapter(List<Estadisticas> estadisticas, Context context) {
        super();
        this.estadisticas = estadisticas;
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.platos_row, parent, false );
        ViewHolder viewHolder = new ViewHolder( v );
        return viewHolder;
    }

    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.root.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //Toast.makeText(context, "this is my Toast message!!! =)",
                        //Toast.LENGTH_LONG).show();

                //Toast.makeText(context, estadisticas.get(position).getEquipo_Local(), Toast.LENGTH_SHORT).show();





                Intent intent= new Intent(context, DetailActivity.class);

                intent.putExtra("Nombre", estadisticas.get(position).getEquipo_Local());
                intent.putExtra("Categoria", estadisticas.get(position).getEquipo_Visitante());
                intent.putExtra("Imagen", estadisticas.get(position).getEscudo_Local());

                context.startActivity(intent);

                //.getText().toString());

                Estadisticas estadisticas1 = estadisticas.get( getAdapterPosition() );
            }

            private int getAdapterPosition() {
                return 0;
            }
        } );
        Estadisticas superHero = estadisticas.get( position );
        imageLoader = DecoracionLineaDivisoria.CustomVolleyRequest.getInstance( context ).getImageLoader();
        imageLoader.get( superHero.getEscudo_Local(), ImageLoader.getImageListener( holder.escudo_local, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert ) );
        holder.escudo_local.setImageUrl( superHero.getEscudo_Local(), imageLoader );
        holder.textViewEquipo_Local.setText( superHero.getEquipo_Local() );
        holder.textViewCategoria.setText( superHero.getEquipo_Visitante() );
    }

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

    class ViewHolder extends RecyclerView.ViewHolder {
        public NetworkImageView escudo_local;
        public TextView textViewEquipo_Local;
        public TextView textViewCategoria;
        public View root;

        public ViewHolder(View itemView) {
            super( itemView );
            root = itemView;
            escudo_local = (NetworkImageView) itemView.findViewById( R.id.tv_esc_local );
            textViewEquipo_Local = (TextView) itemView.findViewById( R.id.tv_ek_local );
            textViewCategoria = (TextView) itemView.findViewById( R.id.tv_ek_visi );
        }
    }
}

DetailActivity.class

public class DetailActivity extends AppCompatActivity {
    private TextView categoria;
    private ImageView imageView;


    //public static final String EXTRA_NAME = "Nombre";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        Intent intent = getIntent();


        categoria = (TextView) findViewById(R.id.tv_info);
        imageView = (ImageView) findViewById(R.id.backdrop);

        String Name = intent.getStringExtra("Nombre");

        TextView categoria = intent.getStringExtra("Categoria");


        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setTitle(Name);
        loadBackdrop();
    }

    private void loadBackdrop() {
        final ImageView imageView = (ImageView) findViewById(R.id.backdrop);
        Glide.with(this).load(imageView).centerCrop().into(imageView);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
}

activity_detail.xml

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin">

            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_info_title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Info"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                <TextView
                    android:id="@+id/tv_info"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="ddddddddddddddd" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/card_margin"
            android:layout_marginLeft="@dimen/card_margin"
            android:layout_marginRight="@dimen/card_margin">

            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/tv_categoria"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Friends"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="aaaa" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/card_margin"
            android:layout_marginLeft="@dimen/card_margin"
            android:layout_marginRight="@dimen/card_margin">

            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Related"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="ddddddddddd" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

This is the error

Error:(36, 51) error: incompatible types: String cannot be converted to TextView

Thanks

    
asked by Rafel C.F 04.01.2017 в 16:31
source

1 answer

1

According to your error:

  

Error: (36, 51) error: incompatible types: String can not be converted   to TextView

The sending and receiving of the values by a bundle is correct, the problem is here:

  TextView categoria = intent.getStringExtra("Categoria");

You must receive a String type:

  String Categoria = intent.getStringExtra("Categoria");

This value can then be used to add it to your TextView categoria :

categoria.setText(Categoria);
    
answered by 04.01.2017 в 16:36