Sunday, 15 April 2012

android - Dynamically creating XML cards -


I am trying to create some layouts dynamically and then flush them. I currently have some layouts and I want to extend them using my own adapter category.

However, now I need to create some cards based on the data that is generated. For example, I tried to use the card class like this

< For pre> (int i = 1; i <10; i ++) {card card = new card (this); Card.setText ("Test" + i); MCards.add (card); }

I can not design how I would like to do this. To do this I have no way to use XML setup because I have more design options like this?

itemprop = "text">

I will post my solution at the risk of downvoting again

To see it now One test is that the way I want it will work. Later I will have the card generated from the actual list, along with the data inside it.

First of all, I have created a text visit to an XML layout within it

   & Lt; / LinearLayout & gt; After that I created an adapter that would increase the layout and set the text view for each item in the list.  
  public class xmlAdapter CardScrollAdapter {Private list & lt ; Integer & gt; MCards; Private layoutInflator aminflator; Public xmlAdapter (list & lt; integer & gt; mCards; layout inflatable flat) {this.mCards = mCards; This.mInflater = inflater; } @ Override Public In Receipt () {return mCards.size (); } @ Override Public Object Getitam (Ent I) {Return Amcrs.Gate (I); } @ Override Public View getView (int i, see View, ViewGroup viewGroup) {View mView = View; See = mInflater.inflate (R.layout.xml_test, view group, incorrect); TextViewText = (TextView) view.findViewById (R.id.test_content); Text.setText ("Test" + mCards.get (i)); View.setTag (text); Return view; } @ Override Public Insecurity (Object O) {return.mCards.indexOf (o); }  

}

And in my activity class I did the following.

onCreate ()

>  CreateCards (); MCardScroller = New CardScrollView (this); MCardScroller.setAdapter (new xmlAdapter (numbercard, getLayoutInflater ())); MCardScroller.setOnItemClickListener (this); Keep in mind that it is only for the loop to insert some data into the list which is being sent to the adapter.  
  Public Zero CreateCards () {For (int i = 1; i & lt; 10; i ++) {numberCards.add (i); }}  

No comments:

Post a Comment