0

In my application i have a String array that i store my strings in it.

private static String[] tokens = new String[1024];

Format of my row which i create it in xml file is:

<TableLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="*"  
android:stretchColumns="*" >
    <TableRow 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_marginTop="10dip"
    android:layout_marginBottom="10dip" >
        <TextView
            android:id="@+id/outstanding_contractdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="15sp" />
        <TextView
            android:id="@+id/outstanding_contractno"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="15sp" />
        <TextView
            android:id="@+id/outstanding_contractamount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textColor="#ffffff"
            android:textSize="15sp" />
    </TableRow>

</TableLayout>

In onCreate(), i defined:

lvOutstanding = (ListView) findViewById(R.id.outstanding_list);
        myListAdapter = new MyListAdapter();
        lvOutstanding.setAdapter(myListAdapter);

and this is my adapter:

class MyListAdapter extends ArrayAdapter<String>{
        MyListAdapter(){
            super(MSOutStanding.this, R.layout.list_outstanding, tokens);
        }

        public View getView(int position, View convertView, ViewGroup parent){
            View row = convertView;

            if(row == null){
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.list_outstanding, parent, false);
            }

            TextView tvContDate = (TextView) row.findViewById(R.id.outstanding_contractdate);
            TextView tvContNo = (TextView) row.findViewById(R.id.outstanding_contractno);   
            TextView tvContAmount = (TextView) row.findViewById(R.id.outstanding_contractamount);

            if(position == 0)
                count = 0;
            else
                count = 3;

            if(arrayLoop>0){
                tvContDate.setText(tokens[position * count]);
                Log.i("Count:", tokens[position * count]);

                tvContNo.setText(tokens[position * count + 1]);
                Log.i("Count:", tokens[position * count +1]);

                tvContAmount.setText(tokens[position * count + 2]);
                Log.i("Count:", tokens[position * count+2]);

                arrayLoop -= 3;
                Log.i("Count:", String.valueOf(arrayLoop));
            }

            return(row);
        }
    }

as you saw, in each row i have three textView and i want to show each three items of array in each row. "arrayLoop" is and int variable that saved number of items in the "tokens[]" array.

Now, when i run the application, emulator shows 1024 rows without any data. where is my mistakes? when i check the logcat (Thanks google for new beautiful design of logCat!), there is no problem and first 12 items in array has parameters and there for (12/3=4), i should see 4 rows with information. However, i have 1024 rows without information :(

enter image description here

2 Answers 2

1

You need to write as follow if tokens tokens array is not string type.

    if(arrayLoop>0){

        tvContDate.setText(String.valueOf(tokens[position * count]));
        Log.i("Count:", tokens[position * count]);

        tvContNo.setText(String.valueOf(tokens[position * count]));
        Log.i("Count:", tokens[position * count +1]);

        tvContAmount.setText(String.valueOf(tokens[position * count]));
        Log.i("Count:", tokens[position * count+2]);

        arrayLoop -= 3;
        Log.i("Count:", String.valueOf(arrayLoop));
    }

Because when you use this tvContAmount.setText(tokens[position * count]); it will think that it is resource id. It will not get this and hence it won't show any output.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. it is not the matter because tokens[] is String and i want to set string in each view.
You have data from log we can conclude that it is looping correctly. The problem is that you can not able to see data. Check by putting tvContDate.setText("Test"); It can able to show text. If yes then then problem is in tokens[] array
0

Your arrayLoop variable must be 0 or less. I think that your problem is where you've put arrayLoop in the if statement you meant to put count. But I can't see where you've defined arrayLoop or what you've assigned to it.

1 Comment

arrayLoop is global variable and the content of it is number of items that i grab from the server. for example (in this case), i garbed 12 items from the server and stored it in tokens array. arrayLoop tells me 12 items out of tokens.lingth, is used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.