Nafees Ahmed
Nafees Ahmed

Reputation: 103

How to make invisible images visible?

I am developing a card game. I divide 13 cards to each client using Server, when I divide 13 cards to 1st player, 9 cards are invisible and remaining 4 are visible. Now I want when I click this one Image, the remaining 9 cards gets visible? How to do this? - the code is this:

String str="  "c,a", "c,k", "c,q", "c,j", "c,10", "c,9", "c,8", "c,7", "c,6", "c,5", "c,4", "c,3", "c,2"";

drawCards(str);

private void drawCards(String drawString) {

    String[] separated = msgLog.split("\\,");


    for (int i = 2; i < separated.length - 1; i += 2) {

        String symbol = separated[i];
        String num = separated[i + 1];
        String resourceName = symbol + num;
        //symbol and number is used for get image from xml file

        int resID = getResources().getIdentifier(resourceName, "id", getPackageName());
        im = (ImageView) findViewById(resID);
        Context context = im.getContext();
        cardID = context.getResources().getIdentifier(resourceName, "drawable", context.getPackageName());

        //9 card invisible       
        if ( i > 10) {
            im.setVisibility(View.GONE);
        }

        /*  elseif(x.getVisibility() == VISIBLE)
        {
            x.setVisibility(INVISIBLE);
        }*/

        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(im.getLayoutParams());
        lp.setMargins(counter * 5, 0, 0, 0);//left,right,top,bottom
        im.setLayoutParams(lp);
        im.setImageResource(cardID);

        im.setOnClickListener(this);

        counter = counter + 8;

    }
}

public void onClick(View v) {

    final String IdAsString = v.getResources().getResourceName(v.getId());

    pieceToast = Toast.makeText(getApplicationContext(), idServer, Toast.LENGTH_SHORT);
    MainActivity.this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            pieceToast.show();
        }
    });

}

When I click this card how to hide card make visible

Upvotes: 2

Views: 608

Answers (2)

Ahmad
Ahmad

Reputation: 742

You can take the help from below given link:

https://stackoverflow.com/questions/41285814/how-to-make-visible-and-invisible-an-image-by-clicking-a-button-in-android-studi

If you still have question, let me know

Upvotes: 1

Gabriella Angelova
Gabriella Angelova

Reputation: 2985

You could play around with the visibility and use the methode setVisibility(View.VISIBLE) and setVisibility(View.GONE)

Upvotes: 0

Related Questions