Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Good day! #548

Open
jerome-savellano opened this issue Aug 9, 2016 · 0 comments
Open

Good day! #548

jerome-savellano opened this issue Aug 9, 2016 · 0 comments

Comments

@jerome-savellano
Copy link

I made a custom card and I can't add a onClickListener to the button inside the card. What am I doing wrong?

`public class CardLearn extends Card {

protected Button btn;
protected TextView tvLorem;

public CardLearn(Context context) {
    super(context, R.layout.native_recyclerview_card_layout);
    init();

}

public CardLearn(Context context, int innerLayout){
    super(context, innerLayout);
    init();
}
private void init(){

    //No Header

    //Set a OnClickListener listener
    setOnClickListener(new OnCardClickListener() {
        @Override
        public void onClick(Card card, View view) {
            Toast.makeText(getContext(), "WOWOWEE", Toast.LENGTH_LONG).show();
        }
    });
}

@Override
public void setupInnerViewElements(ViewGroup parent, View view) {

    btn = (Button) parent.findViewById(R.id.button);
    tvLorem = (TextView) parent.findViewById(R.id.lorem);
    tvLorem.setText("WOWOWEE WOWOWEE WOWOWEE WOWOWEE");

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(), "WOWOWEE", Toast.LENGTH_SHORT).show();
        }
    });

}

}`

Here is the fragment where this card is attached to.

`public class Learn extends Fragment {

public Learn(){
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    final View rootView = inflater.inflate(R.layout.fragment_learn, container, false);

    ArrayList<Card> cards = new ArrayList<Card>();

    CardHeader header = new CardHeader(getActivity());

    for(int i = 0; i<10; i++){
        Card card = new CardLearn(getActivity());
        card.addCardHeader(header);
        cards.add(card);
    }

    CardArrayRecyclerViewAdapter mCardArrayAdapter = new CardArrayRecyclerViewAdapter(getActivity(), cards);

    //Staggered grid view
    CardRecyclerView mRecyclerView = (CardRecyclerView) rootView.findViewById(R.id.carddemo_recyclerview);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    //Set Empty view
    if(mRecyclerView != null){
        mRecyclerView.setAdapter(mCardArrayAdapter);
    }

    return rootView;
}

}`

And here is the XML file of the card

`

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="2">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:weightSum="4"
        android:orientation="vertical"
        android:background="@drawable/overpop">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="3">
        </RelativeLayout>



        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="5dp"
            android:background="#90000000">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Over population"
                android:id="@+id/list_learn_textview"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:textColor="#ccc"
                android:paddingLeft="10dp"
                android:typeface="normal"
                android:visibility="visible" />
        </RelativeLayout>



    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="4">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="3"
            android:padding="10dp">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="@string/lorem_ipsum"
                android:ellipsize="end"
                android:id="@+id/lorem"/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:padding="10dp">


            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LEARN MORE"
                android:id="@+id/button"
                android:layout_centerVertical="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:background="@android:color/transparent"/>
        </RelativeLayout>

    </LinearLayout>

</LinearLayout>

`

Thank you and God bless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant