Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:05:18+00:00 2026-06-10T14:05:18+00:00

I’ve an Activity with two tabs. In the first one there’s a Button .

  • 0

I’ve an Activity with two tabs. In the first one there’s a Button. If this Button is pressed, a new TableRow is created in the second tab. This works fine.

Each TableRow has 3 views(an image, some text and a button). Each time a Button is created i assign an id to it (0,1,2…).

What I want is to set a certain text if the id is 0,1,2…whichever of that ids.

I’ve tried this but it’s not working:

public void onClick(View arg0) {

    // TODO Auto-generated method stub
    switch(arg0.getId()){

        case R.id.save:

            if (et.getText() !=null && thumbnail != null){

                 TableRow tr = new TableRow(this);
                 ImageView view = new ImageView(this);
                 TextView view2 = new TextView(this);
                 Button view3 = new Button(this);
                 view3.setOnClickListener(this);

                 titulo = new String[500];
                 mensaje = new String[500];
                 fotos = new Bitmap[500];

                 view.setImageBitmap(thumbnail);
                 view.setPadding(1, 5, 0, 0);
                 view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

                 Calendar c = Calendar.getInstance();
                 SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");

                 titulo[i]=""+et.getText();
                 mensaje[i]=""+et1.getText();
                 fotos[i]=thumbnail;
                 i++;

                 view2.setText("" + et.getText()  + dateFormat.format(c.getTime()) );
                 view2.setGravity(Gravity.CENTER_HORIZONTAL);
                 view2.setGravity(Gravity.CENTER_VERTICAL);

                 view3.setGravity(Gravity.RIGHT);
                 view3.setGravity(Gravity.CENTER_VERTICAL);

                 DisplayMetrics metrics = new DisplayMetrics();
                 getWindowManager().getDefaultDisplay().getMetrics(metrics);

                 tr.addView(view, metrics.widthPixels/3, 150);
                 tr.addView(view2, metrics.widthPixels/2, 100);
                 tr.addView(view3, metrics.widthPixels/6, 20);
                 tl.addView (tr, 0);


                 final Toast toastMensaje = Toast.makeText(getApplicationContext(),
                            "Tu entrada se cargó correctamente", Toast.LENGTH_LONG);
                    toastMensaje.setGravity(Gravity.CENTER, 0, 0);
                    toastMensaje.show();

                    et.setText("");
                    et1.setText("");
                    i1.setVisibility(View.GONE);


            }

            else{

                final Toast toastMensaje = Toast.makeText(getApplicationContext(),
                        "Tienes que añadir un título y una foto", Toast.LENGTH_LONG);
                toastMensaje.setGravity(Gravity.CENTER, 0, 0);
                toastMensaje.show();

            }


        break;

        case R.id.photo:

            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
            startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);


        break;

        case R.id.gallery:

            Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
             startActivityForResult(intent, TFRequestCodes);

        break;

    }



        for (int j=0; j<titulo.length; j++){

            if (arg0.getId()==j){

            final Toast toastMensaje = Toast.makeText(getApplicationContext(),titulo[j], Toast.LENGTH_LONG);
            toastMensaje.setGravity(Gravity.CENTER, 0, 0);
            toastMensaje.show();

        }

    }








}

What is not working is this piece of code:

        for (int j=0; j<titulo.length; j++){

            if (arg0.getId()==j){

            final Toast toastMensaje = Toast.makeText(getApplicationContext(),titulo[j], Toast.LENGTH_LONG);
            toastMensaje.setGravity(Gravity.CENTER, 0, 0);
            toastMensaje.show();

        }

    }

And this is the XML file:

android:id="@+id/LinearLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TabHost
    android:id="@+id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#001521"
                android:orientation="vertical">


                 <EditText
                    android:id="@+id/title"
                    android:layout_width="fill_parent"
                    android:layout_height="42dp"
                    android:layout_marginTop="5dp"
                    android:hint="Lugar" 
                    android:gravity="top">
                    </EditText>

                 <EditText
                    android:id="@+id/editText1"
                    android:layout_width="fill_parent"
                    android:layout_height="252dp"
                    android:layout_marginTop="3dp"
                    android:hint="Título"
                    android:gravity="top"
                    android:inputType="textMultiLine" ></EditText>

                 <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#001521"
                android:orientation="horizontal">

               <Button
                    android:id="@+id/photo"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:text="Photo" />

               <Button
                    android:id="@+id/gallery"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"
                    android:text="Gallery" />

                <ImageView
                    android:id="@+id/i1"
                    android:layout_width="wrap_content"
                    android:layout_height="50dp"/>


            </LinearLayout>

                <Button
                    android:id="@+id/save"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:text="Guardar entrada"
                     />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >

                <ScrollView
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <TableLayout
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:id="@+id/tl"
                    android:stretchColumns="0,1,2">

                    </TableLayout>

                </ScrollView>

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
            </LinearLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:05:20+00:00Added an answer on June 10, 2026 at 2:05 pm

    You should not initialize those in the onClick()

       titulo = new String[500];
                         mensaje = new String[500];
                         fotos = new Bitmap[500];
    

    By doing so, everytime you click save , new objects are created and you wont be able to store your strings. Move them to onCreate().
    Is i a global variable too?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.