0

I am making an android application containing more than 200 buttons............ Each button respond to an activity...........Each activity contains a button, text view and and image............ Is there any short way so that i could get rid of these many activities and have a single activity with a button and an image.And when i will click a button then it displays me the respective image with a button in that single activity. My main activity containing two buttons named Urdu and English...........

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/main_first_background"
    android:gravity="center"
    android:orientation="vertical" >

<Button
    android:id="@+id/urduForLang"
    android:layout_width="200dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:text="URDU"
    android:textColor="@android:color/background_light" >
</Button>

<Button
    android:id="@+id/EnglishForLang"
    android:layout_width="200sp"
    android:layout_height="80dp"
    android:layout_below="@+id/urduForLang"
    android:layout_gravity="center"
    android:layout_marginTop="2dp"
    android:text="English"
    android:textColor="@android:color/background_light" >
</Button>
</RelativeLayout>

When user click on urdu then it opens up an activity containing 99 buttons and when english is clicked it opens up an activity with same buttons in english. So that i have to make 99 different activities ...which i realy dont want.

when the user touches any button then...then that activity with the respectice image and button will be displayed. Sorry for my english.................

manlio
  • 18,345
  • 14
  • 76
  • 126
areeb
  • 3
  • 1
  • 4

3 Answers3

0

You should make use of Intents and pass some parameter to your Activity in Intent. You can pass your image id, then read it in Activity and decide which image to display.

Please take a look here.

Community
  • 1
  • 1
fgeorgiew
  • 1,194
  • 2
  • 8
  • 25
0

You should use Intents however it might be a lot more useful if you could create one Activity that acts differently according to its paremeters. That way you could set your parameters in the Intent object using Intent.putExtra(...) and then in the Activity that has been invoked, use getIntent().getExtras(). Note that the method getExtras() returns a Bundle object so you need to individually extract all the values you've sent from the main activity from that object. Good luck!

nstosic
  • 2,584
  • 1
  • 17
  • 21
0

Create a single activity and generate your view for that activity at runtime. in this way you may need to write 200 conditions but you will practically save code for 200 Activities.

Jitender Dev
  • 6,907
  • 2
  • 24
  • 35