jeudi 30 juillet 2015

How can I append random numbers and display then on imagebuttons?

I'm trying to do the following but i am stuck and need help.

Currently what i want is,

  1. To be able to hide Random Numbers in my circle ImageButton
  2. To be able to display them once clicked.

I am generating random prime numbers to which i have. Code is here.

    public class hidden {
    int pRandom;

    private int generateNumber(int max) {
        Random rand = new Random();
        return rand.nextInt(max);
    }
}

Now i want to be able to append the random numbers hidden in my imagebutton and once clicked the random numbers apper:

My main activity.

public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ImageButton ib = (ImageButton) findViewById(R.id.imageButton1);
        ib.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hidden.setVisibility(View.Visible);
            }
        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

I have tried this but it is not working. Any help will be appreciated.

my Xml

<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:background="#fffaf4f0">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView" />

    <ImageButton

        android:id="@+id/imageButton1"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:background="@drawable/circle"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="128dp" />

</RelativeLayout>




Aucun commentaire:

Enregistrer un commentaire