-2

TachesFragment.java

package com.example.johnwalls.projet;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;


/**
 * A simple {@link Fragment} subclass.
 */
public class TachesFragment extends Fragment {
    private DB base;
    private ListView sp ;

    public TachesFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment

        View view = inflater.inflate(R.layout.fragment_taches, container, false);

        TextView text2 =  view.findViewById(R.id.ta);//Find textview Id
        TextView t1 =     view.findViewById(R.id.t1);
        TextView de1=     view.findViewById(R.id.de1);
        TextView em1=     view.findViewById(R.id.em1);
        String getArgument = getArguments().getString("main");
        text2.setText(getArgument);


        base=new DB(getActivity());

        text2.setText(getArgument);

        sp=(ListView) view.findViewById(R.id.ta);
        ArrayList<Mission> empList=base.MissionList();
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,empList);
        sp.setAdapter(adapter);





        return view;
    }

}

fragment_taches

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"


    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:gravity="bottom"
    android:orientation="vertical"
    android:background="@drawable/ee63"

    tools:context="com.example.johnwalls.projet.TachesFragment">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="100dp"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"

        android:id="@+id/ta"

        />


</android.support.v4.widget.DrawerLayout>

simple_list_item_1

<?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:layout_height="match_parent"
    android:paddingTop="5dp"
    android:paddingBottom="5dp"
    android:paddingLeft="5dp"
    android:paddingRight="5dp"

    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/t1"
        android:textSize="20dp"
        android:text=""
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/de1"
        android:textSize="10dp"
        android:text=""
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/em1"
        android:textSize="10dp"
        android:text=""
        />


</LinearLayout>

What are you trying to achieve what are you expecting to get out What did you get out (include error messages) What else have you tried? What do you think is causing it? Why do you need to make a new question for it? Why is your problem different to other, similar questions on here?

john walls
  • 47
  • 8

2 Answers2

1

I believe that your issue is that you are telling the ArrayAdapter to expect an Array of String objects (ArrayAdapter<String>) but you are providing an array of Mission objects as per ArrayList<Mission> emplist=base.MissionList();.

i.e. you have

    ArrayList<Mission> empList=base.MissionList(); 
    ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,empList);

Instead I think you need :-

    ArrayList<Mission> empList=base.MissionList(); //<<<< NOT CHANGED
    ArrayAdapter<Mission> adapter=new ArrayAdapter<>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,empList);
  • Note the mission's toString method will be used to provide the data for the list, if you haven't overridden the toString method the result may be not what you expect. e.g.

com.example.johnwalls.projet.Mission@546789

In which case you should create a toString method to return an appropriate string.

As an example (not to be used as it is) here's a TaskData class with an overridden toString method :-

public class TaskData {

    private long id;
    private String type, name, owner, expiration;

    public TaskData(long id, String type, String name, String owner, String expiration) {
        this.id = id;
        this.type = type;
        this.name = name;
        this.owner = owner;
        this.expiration = expiration;
    }

    //<<<< Oreridden toString Method Starts here >>>>
    public String toString() {
        return " Typ: " + type + " Name: " + name + " Owner: " + owner + " Until: " + expiration;
    }
    //<<<< End >>>>

    public long getId(){return id;}
    public String getType() {return this.type;}
    public String getName() {return this.name;}
    public String getOwner() {return this.owner;}
    public String getExpiration() {return  this.expiration;}
}
  • The overridden toString method returns a string that combines the type name and owner and expiration. e.g.

    Type: Test Name: Fred Owner: Bert Until: 31/12/2018

MikeT
  • 51,415
  • 16
  • 49
  • 68
0
    LoveData beanClass = arrayList.get(position);
    Log.e("DisplayPhotolistAdapter","beanClass:"+beanClass);

    tv_date.setText(beanClass.getLOVE_DATE());
    tv_total_percent.setText(beanClass.getPrcentage()+"%");
    tv_hername.setText(beanClass.getHername());
    tv_hisname.setText(beanClass.getHisname());
    tv_Actvity.setText(beanClass.getActvity()+":");