Skip to content Skip to sidebar Skip to footer

How To Display Particular Data From Arraylist Object To Listview?

I am trying to fetch data from .sqlite and display it into the ListView ! For that implemented a GetterSetter class for getting and setting the data in the ArrayList by this method

Solution 1:

You have

String[] values = newString[q.size()]; 
ArrayAdapter<String> adapter = newArrayAdapter<String>(this,
      android.R.layout.simple_list_item_1, android.R.id.text1, values);

But where do you populate items to values array. I don't see that in your code.

You can use Custom ListView with a Custom Adapter

 ArrayList<GS> q = db.getData();
 ListViewlv= (ListView) findViewById(R.id.listView);
 lv.setAdapter(newCustomAdapter(MainActivity.this,q));

CustomAdapter

classCustomAdapterextendsArrayAdapter<GS>
  {
       ArrayList<GS> list;
       LayoutInfalter mInfalter;    
       publicCustomAdapter(Context context, ArrayList<GS> list)
       {
          super(context,R.layout.customlayout,list);
          this.list= list  
          mInfalter = LayoutInfalter.from(context);
       }   
        public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder;
          if(convertView==null)
          {
               convertView = mInflater.inflate(R.layout.customlayout,parent,false);
               holder = new ViewHolder();
               holder.tv1 = (TextView)convertView.findViewById(R.id.textView1); 
               convertView.setTag(holder); 
          }else{
                holder = (ViewHolder)convertVire.getTag();
          } 

                holder.tv1.setText(list.get(postion).getAS_name());
          return convertVIew;
    }
    staticclassViewHolder
    {
        TextView tv1;
    }    
  }

Have a TextView with id textview1 in customlayout.xml.

Or

Using SimpleCursorAdapter would be appropriate in this case.

Post a Comment for "How To Display Particular Data From Arraylist Object To Listview?"