我在这里有这段代码,并且工作正常,但是现在我需要一个带有texview描述的listview,也许是一个位置textview以及一个可绘制的左侧imageview,但是我不知道该怎么做
public class Entreprisesfrag extends android.support.v4.app.Fragment {
public Entreprisesfrag() {
// Required empty public constructor
}
@Override
public void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_entreprises, container, false);
final ListView listView = view.findViewById(R.id.list);
final ArrayList<String> arrayList = new ArrayList<>();
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference();
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(arrayAdapter);
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
\\ This is returning the single-line string
String string = dataSnapshot.getValue(String.class);
arrayList.add(string);
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
menu.clear();
inflater.inflate(R.menu.recherche_activity_menu_item, menu);
MenuItem item = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//Do search code here
return true;
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.recherche)
{
}
else if (item.getItemId()==R.id.filtrer)
{
Toast.makeText(getContext(), "Erreur de connexion ! Vérifiez l'adresse email utilisée et le mot de passe", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:0)
您只需要更改您的simple_list_item_1布局即可显示所需的数据。 使用某种分隔符可以使列中的内容分开。