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 8173729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:15:49+00:00 2026-06-06T22:15:49+00:00

API Level: 12 (Android 3.1) App Background: Through my Android app I am sending

  • 0

API Level: 12 (Android 3.1)

App Background: Through my Android app I am sending a request to our web servers MySQL database to retrieve companies. All of that works fine. Originally I had the returned data populate a ListView, but to get the visual my boss prefers I have 6 TextView‘s evenly distributed. (This app is designed to only work on ONE device, the Samsung Galaxy Tab 10.1)

Question: So, in parsing the returned data I have a for loop. What I would like to do, is auto increment a variable i.e. company_ + i then i++. Is this possible in Java or is there a better way?

Here is an example of how I would think it would work:

int length = 5;

//parse JSON data
try{
    JSONArray jArray = new JSONArray(result);
    for(int i=0; i < length; i++){

        TextView company = (TextView)findViewById(R.id.company_ + i);

        JSONObject jObject = jArray.getJSONObject(i);
            String businessName = jObject.getString("businessName");
            double distance = jObject.getDouble("distance");

            double distRound = 1e5;
            double roDistance = Math.round(distance * distRound) / distRound;

            company.setText(businessName);
            company.append(Html.fromHtml("<br>"));
            company.append("Approximate distance:   " + roDistance + " feet.");

Error Thrown: The operator + is undefined for the argument type(s) TextView, int. Which makes sense, however I am used to working in PHP where I do this often.


Here is my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/location_select"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/row_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2" >

        <TextView
            android:id="@+id/company_1"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="top|left"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/company_2"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="top|right"
            android:layout_marginTop="0dp"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/row_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:layout_below="@id/row_2" >

        <TextView
            android:id="@+id/company_3"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/company_4"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="0dp"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/row_4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:layout_below="@id/row_3" >

        <TextView
            android:id="@+id/company_5"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="bottom|left"
            android:layout_marginLeft="0dp"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />

        <TextView
            android:id="@+id/next_5"
            android:layout_width="0dp"
            android:layout_height="200dp"
            android:layout_gravity="bottom|right"
            android:layout_marginRight="0dp"
            android:layout_weight="1"
            android:textIsSelectable="true"
            android:textSize="25sp" />
    </LinearLayout>

</RelativeLayout>
  • 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-06T22:15:50+00:00Added an answer on June 6, 2026 at 10:15 pm

    If Textview remains constant, then you can do this..

    int[] companyIds = { R.id.company_id_1,
            R.id.company_id_2, R.id.company_id_3,...};
    

    and in code do this

    TextView company_select = (TextView)findViewById(companyIds[i]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an Android (API level 7) app in Eclipse 3.7.2. I have
I selected API minimum level 1.5 for my android app and I'm just about
Building an app using android.support.v4.app , targeting API level 8. Everything's working as planned
I'm developing an app for Android in Eclipse. Currently I target API level 3,
Javadoc says: void android.app.Activity.showDialog(int id) public final void showDialog (int id) Since: API Level
I'm developing an Android app (API level 8). How do I add some right
I am developing an Android App @ 1.6 API level. I need to adjust
I have an Android app that has a minimum API level of 4 (Android
We recently tested our application against android API level 14 and 15. We started
I am using 'jquery-ui-map' for an android app. My emulator is Google API Level

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.