3

I am having trouble in displaying the values in text view. It displays only the last value in text view. I want to iterate each and every value in new line.

Here is my code.

PreviewCatNameTxt = new TextView[obdatin.catCount];
        PreviewNameTxt = new TextView[10];
        PreviewQtyTxt = new TextView[10];
        PreviewAmtTxt = new TextView[10];
        System.out.println("setview3");
        for(int i=0;i<obdatin.catCount;i++){ 
            System.out.println("num oof prca"+obdatin.catList[i].getNumCategory());
            if(obdatin.catList[i].isTotQtyNonZero(0)){
                PreviewCatNameTxt[i] = (TextView) findViewById(R.id.textViewh);

                PreviewCatNameTxt[i].setText(obdatin.catList[i].getCategoryName(0));
                System.out.println("prca"+obdatin.catList[i].getCategoryName(0));
            }
            int cnt =obdatin.catList[i].proList.getNumProduct();
        System.out.println("setview3");

        for(int j = 0; j<cnt; j++) {

            if(obdatin.catList[i].proList.isQtyNonZero(j)){

                PreviewNameTxt[j] = (TextView)findViewById(R.id.textView1);
                PreviewNameTxt[j].setText(obdatin.catList[i].proList.getProductName(j));

                PreviewQtyTxt[j] = (TextView)findViewById(R.id.textView2);

                PreviewQtyTxt[j].setText(obdatin.catList[i].proList.getProductQty(j));

                PreviewAmtTxt[j] = (TextView)findViewById(R.id.textView3);
                String amt = obdatin.catList[i].proList.getProductAmt(j);
                PreviewAmtTxt[j].setText(amt);
                System.out.println("prcaN"+obdatin.catList[i].proList.getProductName(j));
                System.out.println("prcaQ"+obdatin.catList[i].proList.getProductQty(j));
                System.out.println("prcaA"+obdatin.catList[i].proList.getProductAmt(j));
             }

        }
1
  • Please see my answer. I think your problem will be solved. If you any further query then please ask me. Commented Jan 8, 2014 at 6:35

4 Answers 4

3

Edited Code as per your requirement

PreviewCatNameTxt = (TextView) findViewById(R.id.textViewh);


for(int i=0;i<obdatin.catCount;i++){ 
            System.out.println("num oof prca"+obdatin.catList[i].getNumCategory());
            if(obdatin.catList[i].isTotQtyNonZero(0)){


                PreviewCatNameTxt.append(" "+obdatin.catList[i].getCategoryName(0));
                System.out.println("prca"+obdatin.catList[i].getCategoryName(0));
            }
            int cnt =obdatin.catList[i].proList.getNumProduct();
        System.out.println("setview3");

        for(int j = 0; j<cnt; j++) {

            if(obdatin.catList[i].proList.isQtyNonZero(j)){


                   PreviewCatNameTxt.append("\n"+obdatin.catList[i].proList.getProductName(j));

                PreviewCatNameTxt.append("\n"obdatin.catList[i].proList.getProductQty(j));

                String amt = obdatin.catList[i].proList.getProductAmt(j);
                PreviewCatNameTxt.append("\n"+amt+"\n\n");
                System.out.println("prcaN"+obdatin.catList[i].proList.getProductName(j));
                System.out.println("prcaQ"+obdatin.catList[i].proList.getProductQty(j));
                System.out.println("prcaA"+obdatin.catList[i].proList.getProductAmt(j));
             }

Please remove TextView array and all those things. Please reply your feedback.

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

10 Comments

here textview is an array how can i declare outside of the loop
Ok so declare it inside but avoid setText and do append. I will edit my answer as per your need
but if you declare inside then it will every time create new textview so, previous id data will be missed ? can you try using my code? is my code workable?
i want to show the output as in firstline heading next line n number of rows again heading and next line n number of rows actually i used table layout by help of inflater to achive this but i got failed in that one..so i used to choose this way can you suggest me some idea
great bro..i used tablelayout
|
1

I am not entirely sure what you are trying to do.Why do you use System.out.println?

If I got it right you want a larger text to be put in TextView separated by newlines after each loop of the for. One way to do it is to have a String which you fill with every iteration, also adding a newline after each iteration and after the for setting the text.

So, you could have something like this:

String catList="";
for(int i=0;i<obdatin.catCount;i++){
        if(obdatin.catList[i].isTotQtyNonZero(0)){
        catList = catList + obdatin.catList[i].getCategoryName(0) + "\n";
        }
int cnt =obdatin.catList[i].proList.getNumProduct();

PreviewCatNameTxt[i] = (TextView) findViewById(R.id.textViewh);
PreviewCatNameTxt[i].setText(catList);

Also, if you want to log something you should od to use LogCat. You can read about Reading and Writing in LogCat here and here. Good luck!

1 Comment

i want to show the output as in firstline heading next line n number of rows again heading and next line n number of rows actually i used table layout to achive this but i got failed in that one..so i used to choose this way can you suggest me some idea
1
PreviewNameTxt[j] = (TextView)findViewById(R.id.textView1);
PreviewQtyTxt[j] = (TextView)findViewById(R.id.textView2);
PreviewAmtTxt[j] = (TextView)findViewById(R.id.textView3);
String cat="",obtaincat="",amt="";

for(int j = 0; j<cnt; j++) {

            if(obdatin.catList[i].proList.isQtyNonZero(j)){

                cat = cat + obdatin.catList[i].getCategoryName(j) + "\n";
                obtaincat=btaincat+obdatin.catList[i].proList.getProductQty(j)+"\n";
               amt =amt+ obdatin.catList[i].proList.getProductAmt(j)+"\n";
             }
}
PreviewNameTxt[j].setText(cat);
PreviewQtyTxt[j].setText(obtaincat);
PreviewAmtTxt[j].setText(amt);

1 Comment

don't use System.out.println();,for cheking output use toast
-1

Change to Logcat :

Log.w("","prcaN"+obdatin.catList[i].proList.getProductName(j));
Log.w("","prcaQ"+obdatin.catList[i].proList.getProductQty(j));
Log.w("","prcaA"+obdatin.catList[i].proList.getProductAmt(j));

Comments

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.