0

I have a doubt in listview android. I am getting 3 dynamic values from service. I am using my own Arraylist Adpater. I have 3 textviews. I am able to get the data from service. I need to know how can i place the 3 values in individual textview of the listview.

sample code:

buddyNameList[i] = r.getName() + status; 
            //buddyNameLists[i] = status;
                //RowData rd;
                for(i=0;i<buddyNameList[i].length();i++){



                //buddyJidList[i] = r.getUser();
                // Intent myIntent = new Intent(this,DataHelper.class);
                // myIntent.putExtra("UJID", mydata);
                // startActivity(myIntent);
                // dh.insertBuddy(r.getUser(),r.getName());
                i++;
                ListAdapter adapter = new ArrayAdapter<String>(this,
                        R.layout.custom_row_view,R.id.name     ,buddyNameList); // here i can append one value in 1 textview. i need to display all 3            //values from service in 3 individual textview in listview

                lv.setAdapter(adapter);

I need to know how to place values of all 3 data in corresponding cell in listview Kindly guide me how can i achive the result.

Thanks in advance. }

2 Answers 2

1

You can try this. we can add many textviews dynamically.

String[] name =
    {
        "Apple",
        "Banana",
        "Orange",
        "Mango",
        "Grapes",
        "Jack Fruit",
        "Strawberry",
        "cucumber",
        "pumpkin",
        "pine Apple"
    };
String[] age =
    {
        "20",
        "21",
        "22",
        "23",
        "24",
        "25",
        "26",
        "27",
        "28",
        "29"
    };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


   TableLayout tv=(TableLayout) findViewById(R.id.table1);
    tv.removeAllViewsInLayout();

    int Fruits_length=name.length;
    int i=0;

    while(i<Fruits_length)
    {


    String str1 = "<font color=#0099ff>Name</font> <br/> <font color=#ffffff> "+name[i]+" </font>";

    String str2="<font color=#0099ff>Age</font> <br/> <font color=#ffffff> "+age[i]+" </font>";


    final TableRow tr=new TableRow(Listview2Activity.this);

        tr.setLayoutParams(new LayoutParams(
                   LayoutParams.FILL_PARENT,
                   LayoutParams.WRAP_CONTENT));


             tr.setId(i);



            final TextView b1=new TextView(Listview2Activity.this);
               b1.setTextSize(15);
               b1.setText(Html.fromHtml(str1));
               b1.setWidth(200);
            tr.addView(b1);

            final TextView b2=new TextView(Listview2Activity.this);
            b2.setTextSize(15);
            b2.setText(Html.fromHtml(str2));
            b2.setWidth(200);
         tr.addView(b2);


             tr.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape));
           tv.addView(tr);


        final View vline1 = new View(Listview2Activity.this);
      vline1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
      vline1.setBackgroundColor(Color.GREEN);
      tv.addView(vline1);      


                tr.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {


                        String e=String.valueOf(tr.getId());

                        Toast.makeText(getApplicationContext(), e, Toast.LENGTH_SHORT).show(); 


                    }
                });

    i=i+1;
    }


}

}

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

Comments

0

Use a custom BaseAdapter. In the getView of the adapter, inflate your layout and give values for the textViews. Refer http://developer.android.com/reference/android/widget/BaseAdapter.html

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.