empty row in listview - android

I created a listView which I associated with a adapter. Problem is that rows appear empty even if I set the textview from the view which was created. I mention that the number of rows from listview is right. Thank you.
shopping_page_item
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/productTitle"
android:layout_width="0dp"
android:layout_height="47dp"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Adapter
public class ShoppingListAdapter extends ArrayAdapter<String> {
public ShoppingListAdapter(Context context, String content[]) {
super(context, R.layout.shopping_page_item, content);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.shopping_page_item, parent, false);
}
TextView editText = convertView.findViewById(R.id.productTitle);
editText.setText(getItem(position).toString());
return convertView;
}
}

Try this
<TextView
android:id="#+id/productTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Your parent layout's height is match_content, make it wrap_content. It may be possible that your one row covering the complete screen.

Related

Linear View in ScrollView with Array Adapter growing up instead of down on new items

I have an Java Android project I am working on wherein I have a LinearLayout that is managed by an array adapter.
My issue is when I add a new item to the array adapter and update the view the List of items is growing upwards instead of down as is visible in the images below.
Why is this now growing down? and how can i make it do so?
Code follows pics
Main Activity
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<AnalogClock
android:id="#+id/clockMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.1" />
<TextView
android:id="#+id/dateMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/clockMain"
/>
<TextView
android:id="#+id/titleMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/annie_use_your_telescope"
android:text="#string/app_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/dateMsg"
app:layout_constraintVertical_bias="0.05"
android:textSize="30sp"
android:textColor="#color/colorPrimaryDark"
/>
<ListView
android:id="#+id/taskList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.5"
android:nestedScrollingEnabled="true"
/>
<Button
android:id="#+id/addNewTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add_new_task"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.95"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Task List
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/taskDesc"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:textSize="15sp"
android:text="testing task"
android:layout_weight="1"
/>
<TextView
android:id="#+id/taskDate"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="this is bull shit"
android:layout_weight="1"
/>
<TextView
android:id="#+id/taskTime"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="some more bullish"
android:layout_weight="1"
/>
</LinearLayout>
inflator
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.task_list, null);
TextView taskDesc = (TextView) view.findViewById(R.id.taskDesc);
TextView taskDate = (TextView) view.findViewById(R.id.taskDate);
TextView taskTime = (TextView)view.findViewById(R.id.taskTime);
taskDesc.setText(tasks.get(i).description);
taskDate.setText(tasks.get(i).taskDate.toString());
taskTime.setText(tasks.get(i).taskTime.toString());
return view;
}
import java.util.ArrayList;
public class TaskAdapter extends BaseAdapter {
Context context;
LayoutInflater inflater;
ArrayList<Task> tasks;
public TaskAdapter(Context applicationContext, ArrayList<Task> tasks) {
this.context = applicationContext;
this.tasks = new ArrayList<>(tasks);
inflater = (LayoutInflater.from(applicationContext));
}
#Override
public int getCount() {
return tasks.size();
}
#Override
public Object getItem(int i) {
return null;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.task_list, null);
TextView taskDesc = (TextView) view.findViewById(R.id.taskDesc);
TextView taskDate = (TextView) view.findViewById(R.id.taskDate);
TextView taskTime = (TextView)view.findViewById(R.id.taskTime);
taskDesc.setText(tasks.get(i).description);
taskDate.setText(tasks.get(i).taskDate.toString());
taskTime.setText(tasks.get(i).taskTime.toString());
return view;
}
}
Can you add the array adapter you are using(how you are inserting data in arrayadapter) and where you are passing the array to listview.

Trouble with ListView

I have an issue with my Main Activity and a ListView and I absolutly don't understand how it works...
OK ! This is what I want :
Expectation
It means I need a list of item : TextViews
And OUTSIDE of this list a simple button. I don't want the button to be part of the list.
But here is what I have :
Reality
As you can see, in every child of my list i have my text AND my button : Why ??
My code Main :
public class MainMenu extends AppCompatActivity implements IRemDeck, IRemCard {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
ListView listView = findViewById(R.id.MainDecksList);
AdapterDeck adpDeck;
ArrayList<Deck> myDecks = new ArrayList<>();
for (int i = 0; i<5;i++){
myDecks.add(new Deck("Deck " + i));
}
adpDeck = new AdapterDeck(this, 0, myDecks);
listView.setAdapter(adpDeck);
}
My Adapter (for the ListView) :
public AdapterDeck(#NonNull Context context, int resource, #NonNull ArrayList<Deck> decks) {
super(context, resource, decks);
this.decks = decks;
this.context = context;
}
#Override
public int getCount() {
return decks.size();
}
#Override
public Deck getItem(int pos) {
return decks.get(pos);
}
#Override
public long getItemId(int pos) {
return 0;
//just return 0 if your list items do not have an Id variable.
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.activity_main_menu, null);
}
//Handle TextView and display string from your list
TextView listItemText = view.findViewById(R.id.MainDeckNom);
listItemText.setText(decks.get(position).getNom());
return view;
}
The XML :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainMenu">
<TextView
android:id="#+id/MainDeckNom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/MainDecksList"
android:layout_width="363dp"
android:layout_height="426dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/MainDecksList" />
</android.support.constraint.ConstraintLayout>
If someone could explain to me how to solve my problem (and how it works eventually) I would be very grateful !
Thanks a lot :)
listview has to have its own layout, so you need to create a new layout that just contains listview and in getView() method use it as a row of your listView
1- create a new row_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainMenu">
<TextView
android:id="#+id/MainDeckNom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
2-Change this line
view = inflater.inflate(R.layout.activity_main_menu, null);
to
view = inflater.inflate(R.layout.row_listview, null);
In your adapter's getView() method, you have to design a child_view layout. The layout which you return will be show in every item of the list. Because you're returning main_activity_layout so every your item would show the mainAcitivy, which contains a button. Solution is create new layout with your own design and replace it with R.layout.main_acitivity_layout. Good luck
You should not use R.layout.activity_main_menu in getView, because getView returns a line of the list which you don't want to have a button.
So, you have a separate layout activity_main_men specified as Content view for the activity which does not have TextView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainMenu">
<ListView
android:id="#+id/MainDecksList"
android:layout_width="363dp"
android:layout_height="426dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/MainDecksList" />
</android.support.constraint.ConstraintLayout>
The in getView instead of
view = inflater.inflate(R.layout.activity_main_menu, null);
you just place:
view = new TextView()
view.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

Making custom layout that should fullfit the spinner

My spinner is constrained to guidelines and changes it size depending on the screen size. And then it comes my problem. I have this
its custom_spinner.XML
Its width and height is match constraint
My CustomAdapter
public class MyCustomSpinnerAdapter extends ArrayAdapter<MySpinnerData>
{
private Context context;
private List<MySpinnerData> spinnerData;
private boolean Car = false;
private String initialText;
private boolean alignLeft = false;
public MyCustomSpinnerAdapter(#NonNull Context context,#LayoutRes int resource,List<MySpinnerData> spinnerData)
{
super(context, resource,spinnerData);
spinnerData = spinnerData;
context = context;
}
#NonNull
#Override
public View getView(int position, #Nullable View convertView, #NonNull ViewGroup parent)
{
return myCustomSpinnerView(position, convertView, parent );
}
#Override
public View getDropDownView(int position, #Nullable View convertView, #NonNull ViewGroup parent)
{
return myCustomSpinnerView(position, convertView, parent);
}
private View myCustomSpinnerView(int position, #Nullable View myView, #NonNull ViewGroup parent)
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customview = layoutInflater.inflate(R.layout.spinner_layout,parent,false);
TextView textView = (TextView)customview.findViewById(R.id.textView);
textView.setText(spinnerData.get(position).getIconName()); //function that set text
return customview;
}
}
This is what i get
This is custom_spinner.XML
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#drawable/my_border"
android:fadeScrollbars="false"
android:fontFamily="#font/titillium_web"
android:gravity="center_horizontal|center_vertical"
android:text="simple"
android:textColor="#android:color/background_light"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline4"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/guideline2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="23dp"
android:layout_height="23dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="#+id/textView"
app:layout_constraintStart_toStartOf="#+id/textView"
app:layout_constraintTop_toTopOf="#+id/textView"
app:srcCompat="#drawable/autic" />
<android.support.constraint.Guideline
android:id="#+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.00" />
<android.support.constraint.Guideline
android:id="#+id/guideline4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="1" />
And this is activity_main.XML (spinner)
<Spinner
android:id="#+id/Tablice"
android:layout_width="0dp"
android:layout_height="89dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="6dp"
android:layout_marginTop="8dp"
android:background="#null"
android:popupBackground="#color/uplatiParkingDugme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/TablicaDugme"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="#+id/guideline"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.25"
/>
Width fullfit great , but as soon as i set match constraint as a width parameter of custom_spinner, a dropdown items wont show?
Can anyone help me? Im stuck on this for a weeks..
After i add
customview.measure(0,0);
In MyCustomSpinnerView method, it works
But it displays items with low height , not the height of actual spinner?
What does measure function do , and why it works now?

RecyclerView.Adapter never calls onCreateViewHolder

After searching for hours I can't find a solution to my problem. I have the following classes:
Main activity:
RecyclerView rvIdeas = (RecyclerView) findViewById(R.id.recView1);
// Initialize ideas
DaoSession daosession = ((App) getApplication()).getDaoSession();
IdeaDao ideadao = daosession.getIdeaDao();
ideas = (ArrayList<Idea>) ideadao.loadAll();
// Set layout manager to position the items
rvIdeas.setLayoutManager(new LinearLayoutManager(this));
// Create adapter passing in the list of ideas
IdeaAdapter adapter = new IdeaAdapter(this, ideas);
// Attach the adapter to the recyclerview to populate items
rvIdeas.setAdapter(adapter);
Then the adapter:
public class IdeaAdapter extends
RecyclerView.Adapter<IdeaAdapter.ViewHolder> {
// Provide a direct reference to each of the views within a data item
// Used to cache the views within the item layout for fast access
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView ideaname;
public TextView docCount;
public TextView last_mod;
// We also create a constructor that accepts the entire item row
// and does the view lookups to find each subview
public ViewHolder(View itemView) {
// Stores the itemView in a public final member variable that can be used
// to access the context from any ViewHolder instance.
super(itemView);
ideaname = (TextView) itemView.findViewById(R.id.main_idea_name);
docCount = (TextView) itemView.findViewById(R.id.idea_documents);
last_mod = (TextView) itemView.findViewById(R.id.idea_last_edited);
}
}
// Store a member variable for the ideas
private List<Idea> ideas;
// Store the context for easy access
private Context mContext;
// Pass in the idea array into the constructor
public IdeaAdapter(Context context, List<Idea> ideaList) {
ideas = ideaList;
mContext = context;
}
// Easy access to the context object in the recyclerview
private Context getContext() {
return mContext;
}
// Usually involves inflating a layout from XML and returning the holder
#Override
public IdeaAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
// Inflate the custom layout
View ideaView = inflater.inflate(R.layout.item_idea, parent, false);
// Return a new holder instance
return new ViewHolder(ideaView);
}
// Involves populating data into the item through holder
#Override
public void onBindViewHolder(IdeaAdapter.ViewHolder viewHolder, int position) {
// Get the data model based on position
Idea idea = ideas.get(position);
// Set item views based on your views and data model
viewHolder.ideaname.setText(idea.getName());
String docs = R.string.media + idea.getName();
viewHolder.docCount.setText(docs);
viewHolder.last_mod.setText(idea.getLast_modified().toString());
}
// Returns the total count of items in the list
#Override
public int getItemCount() {
return ideas.size();
}
}
And the .xml of fragment_main:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
tools:context=".view.fragments.MainFragment">
<android.support.v7.widget.RecyclerView
android:id="#+id/rvIdea"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:visibility="visible" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_insert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="325dp"
android:layout_marginStart="325dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="465dp"
android:adjustViewBounds="false"
android:baselineAlignBottom="false"
android:clickable="true"
android:nestedScrollingEnabled="true"
android:onClick="addFABclick"
app1:pressedTranslationZ="24dp"
app:layout_behavior=".view.animation.ScrollAwareFABBehavior"
app:srcCompat="#drawable/material_add_white" />
</android.support.design.widget.CoordinatorLayout>
Last but not least the layout for the recyclerview:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/main_idea_name"
android:layout_width="210dp"
android:layout_height="20dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="10dp"
android:textAppearance="#android:style/TextAppearance.Medium"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/idea_documents"
android:layout_width="210dp"
android:layout_height="20dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="0dp"
android:textColor="#color/black"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/main_idea_name" />
<ImageView
android:id="#+id/idea_share"
android:layout_width="28dp"
android:layout_height="31dp"
app:srcCompat="?attr/actionModeShareDrawable"
app:layout_constraintRight_toLeftOf="#+id/idea_go_inside"
android:layout_marginRight="22dp"
android:layout_marginEnd="22dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:contentDescription="#string/share"/>
<ImageView
android:id="#+id/idea_go_inside"
android:layout_width="29dp"
android:layout_height="30dp"
app:srcCompat="#drawable/material_arrow_right"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintRight_toRightOf="parent"
android:contentDescription="#string/go_next"/>
<ImageView
android:id="#+id/idea_trash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#android:drawable/ic_menu_delete"
app:layout_constraintRight_toLeftOf="#+id/idea_share"
android:layout_marginRight="14dp"
android:layout_marginEnd="14dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toRightOf="#+id/idea_documents"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
app:layout_constraintHorizontal_bias="1.0"
android:contentDescription="#string/trash"/>
<TextView
android:id="#+id/idea_last_edited"
android:layout_width="210dp"
android:layout_height="20dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="8dp"
android:layout_marginStart="16dp"
android:layout_marginTop="0dp"
android:textColor="#color/colorSecondaryText"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/idea_documents" />
</android.support.constraint.ConstraintLayout>
The problem is that onBindViewHolder and onCreateViewHolder are never called. getItemCount returns something > 0 and there are no null pointers or nested scrolls. The recyclerview displays nothing. What am I doing wrong?
Thanks for any help.

Custom Spinner with default down arrow in it

I have a custom layout for spinner. Its both selected and dropdown list item's background color will change depending on user demand. So i am changing depending on their values.. so far so good. But the problem is since i am using custom layout or changing background color, there is no arrow to show that it is a spinner. When i add arrow from layout then all even dropdown list have that arrow with them. I can manipulate it by setting arrow's background to null for drop down items but it is not a good way and dont always work. So how can i show spinner default arrow with my custom spinner without using spinner style. Dont forget that i am changing background of every item.
Here is my custom_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:weightSum="6" android:id="#+id/spinnerMainLayout"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal" android:layout_width="match_parent"
android:weightSum="14"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp" android:layout_marginTop="8dp"
android:layout_height="wrap_content" android:layout_marginLeft="10dp"
android:text="New Text" android:textSize="19sp" android:layout_weight="5"
android:layout_gravity="center" android:layout_marginBottom="8dp"
android:gravity="center" android:layout_marginRight="4dp"
android:id="#+id/type" android:typeface="serif"/>
<View
android:layout_width="1dp" android:layout_marginLeft="8dp" android:layout_marginTop="4dp"
android:layout_height="match_parent" android:layout_marginBottom="4dp"
android:background="#666666" />
<TextView
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_weight="9"
android:typeface="serif" android:maxLines="3" android:minLines="2"
android:layout_gravity="center" android:layout_marginBottom="8dp"
android:layout_marginLeft="10dp" android:layout_marginRight="5dp"
android:text="sd" android:textSize="18sp" android:gravity="center_vertical"
android:id="#+id/history" />
</LinearLayout>
</LinearLayout>
and here is my custom spinner class
class CustomSpinner extends ArrayAdapter<String> {
private String[] fixStrs = new String[]{"Definition","Result","Error"};
public CustomSpinner(Context ctx, int txtViewResourceId, String[] objects) {
super(ctx, txtViewResourceId, objects);
//fixStrs = objects;
}
#Override public View getDropDownView(int position, View cnvtView, ViewGroup prnt) {
return getCustomView(position, cnvtView, prnt);
}
#Override public View getView(int pos, View cnvtView, ViewGroup prnt) {
return getCustomView(pos, cnvtView, prnt);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View mySpinner = inflater.inflate(R.layout.custom_spinner, parent, false);
/*LinearLayout spinnerMain = (LinearLayout) mySpinner.findViewById(R.id.spinnerMainLayout);
spinnerMain.setBackgroundColor(Color.parseColor(colors[0]));*/
TextView fixText = (TextView) mySpinner.findViewById(R.id.type);
fixText.setText(fixStrs[position]);
fixText.setTextColor(Color.parseColor(colors[1]));
TextView historyText = (TextView) mySpinner.findViewById(R.id.history);
historyText.setText(history[position]);
historyText.setTextColor(Color.parseColor(colors[1]));
return mySpinner;
}
}
Create a different layout for the spinner dropdown and pass it to the .setDropDownViewResource method of the ArrayAdapter, then you must specify the id of the textview in this layout in the constructor call of your adapter

Categories

Resources