How to pass image and text to an onclick listview

0

I am trying to pass infromation to a listview when the user clicks on a botton. Until now the written information is passed to the listview, but I would like to have a default image for each text and look something like:

[[[ Imagen ]]] Texto aqui aqui aqui aqui
[[[ Imagen ]]] Texto aqui aqui aqui aqui
[[[ Imagen ]]] Texto aqui aqui aqui aqui
[[[ Imagen ]]] Texto aqui aqui aqui aqui
[[[ Imagen ]]] Texto aqui aqui aqui aqui

but esoty a bit lost in how to achieve this .... with the following code the text is passed successfully and you look in the listview.

public class List extends Fragment {

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        listView = (ListView) getView().findViewById(R.id.chatList);
        AddButton = (Button) getView().findViewById(R.id.buttonT);
        GetValue  = (EditText) getView().findViewById(R.id.chatT);

        final List<String> ListElementsArrayList = new ArrayList<String>(Arrays.asList(ListElements));
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, ListElementsArrayList);
        listView.setAdapter(adapter);

        AddButton.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                ListElementsArrayList.add(GetValue.getText().toString());
                adapter.notifyDataSetChanged();
                GetValue.setText("");
            }
        });
}

XML

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="330dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentTop="true"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="21dp"
            android:orientation="horizontal">

            <ListView
                android:id="@+id/chatList"
                android:layout_width="734dp"
                android:layout_height="match_parent"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:dividerHeight="2.0sp"
                android:layout_marginStart="16dp" />


        </RelativeLayout>
    
asked by Pedro 31.07.2018 в 20:26
source

0 answers