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>
你想达到什么你期望得到什么 你得到了什么(包括错误消息) 你还尝试了什么?你认为是什么原因造成的?为什么你需要为它提出一个新问题?为什么您的问题与此处的其他类似问题不同?
我相信您的问题是您告诉ArrayAdapter
Array of String 对象 ( ArrayAdapter<String>
) 但您提供了一组Mission对象ArrayList<Mission> emplist=base.MissionList();
。
即你有
ArrayList<Mission> empList=base.MissionList();
ArrayAdapter<String> adapter=new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,android.R.id.text1,empList);
相反,我认为你需要:-
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);
toString
方法将用于为列表提供数据,如果您没有覆盖该toString
方法,结果可能与您预期的不同。例如com.example.johnwalls.projet.Mission@546789
在这种情况下,您应该创建一个toString
方法来返回适当的字符串。
作为一个例子(不要按原样使用),这是一个带有重写toString
方法的 TaskData 类:-
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;}
}
类型:测试名称:Fred所有者:Bert直到:31/12/2018
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句