Good day, dear colleagues. During development, there was a desire to make the list items in a similar way as Google does (rectangles with text).
the question is how to implement? I work with Android recently, only Listview consisting of Fragment climbs into my head. Put the traveler on the right path, I will be grateful for such implementations.
2 answers
1.In Layout Activity post
<ListView android:id="@+id/lvMain" android:layout_width="match_parent" android:dividerHeight="5dp"<!--ширина разделителя--> android:layout_height="wrap_content"> </ListView> 2. In aktivti create a variable
ListView lvMain = (ListView) findViewById(R.id.lvMain); 3. Create an Adapter to which the necessary values will be transmitted (instead of names your array of values):
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names); Create a
Layoutsimple_list_item_1and in it implement how everything should be displayed in one cell.Assign
AdaptertoListView
lvMain.setAdapter(adapter);
Hi, recently there was a development where it was necessary to use cards (CardView), yes yes it’s Google cards. So after a short search, I found this https://github.com/gabrielemariotti/cardslib
First you download cardslib-core, then the modules you need. Create a card
ColorCard card = new ColorCard(this.getActivity()); card.setTitle("A simple colored card " + i); Create adapter
mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards); Throw a card in the adapter
ArrayList<Card> cards = new ArrayList<Card>(); cards.add(card); mCardArrayAdapter = new CardArrayAdapter(getActivity(), cards); I screw the adapter to CardListView and add some animations
mListView = (CardListView) getActivity().findViewById(R.id.carddemo_extra_list_viewanimations); AnimationAdapter animCardArrayAdapter = new AlphaInAnimationAdapter(mCardArrayAdapter); animCardArrayAdapter.setAbsListView(mListView); if (mListView != null) { mListView.setExternalAdapter(animCardArrayAdapter,mCardArrayAdapter); }
compile 'com.android.support:cardview-v7:21.0.+'- tim_taller