Rendering problem in customlistview?

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Rendering problem in customlistview?

Postby hitendra » Mon Jan 03, 2011 9:49 am

hi,
I am just trying to make one simple customlistview.below is my code.
The problem is that as image icon shows in all 10 rows but strings are shows only to first 1 or 2 rows.
Code: Select all
package com.demo.list;

import java.util.ArrayList;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MyCustomListView extends ListActivity {
   private ArrayList<String> m_orders=null;
   private OrderAdapter m_adapter;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        m_orders = new ArrayList<String>();
        for(int i=0;i<10;i++)
        {
           m_orders.add("Android List");
        }
        this.m_adapter = new OrderAdapter(this, R.layout.row, m_orders);
                setListAdapter(this.m_adapter);
    }
    private class OrderAdapter extends ArrayAdapter<String>
    {
       private ArrayList<String> items;
       public OrderAdapter(Context context,int id,ArrayList<String> items)
       {
          super(context,id,items);
          this.items=items;
       }
       public View getView(int position,View convertView,ViewGroup parent)
       {
          View view=convertView;
          if(view==null)
          {
             LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
             view=inflater.inflate(R.layout.row,null);
          }
          String string=items.get(position);
          if(string!=null)
          {
             TextView t1=(TextView)findViewById(R.id.toptext);
             TextView t2=(TextView)findViewById(R.id.bottomtext);
             if(t1!=null)
             {
                t1.setText("Name:-"+string.toString());
             }
             if(t2!=null)
             {
                t2.setText("Status:-"+string.toString());
             }
          }
          return view;
       }
    }
}

thankx
hitendra
Freshman
Freshman
 
Posts: 4
Joined: Fri Dec 31, 2010 9:53 am

Top

Return to General

Who is online

Users browsing this forum: Google [Bot] and 8 guests