Nombre del fragment: ClienteFragmen
En el telefono:
En el telefono:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.cliente.ClienteFragment"
android:orientation="vertical">
<ListView android:id="@+id/listview_cliente"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:dividerHeight="10dp" />
</LinearLayout>
En mi ClienteFragment.java:
public class ClienteFragment extends Fragment {
private View v;
private ListView listView;
String[] elementos = {"Amelia Perez", "Estilita Barrios", "Haroldo Montero", "Nelson Adolfo", "Andrea Hernandez", "Lorena Salas", "Dayana Rosales", "Leonarda Vidal", "Sofia Diaz"};
private ClienteViewModel mViewModel;
public static ClienteFragment newInstance() {
return new ClienteFragment();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
v=inflater.inflate(R.layout.cliente_fragment, container, false);
View root = v;
final ListView listView = root.findViewById(R.id.listview_cliente);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_expandable_list_item_1,elementos);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Item: " + id +"", Toast.LENGTH_SHORT).show();
}
});
return v;
}

No hay comentarios:
Publicar un comentario