Enviado em 22/11/2018 - 13:17h
Prezados,
package br.com.drsolutions.duvidabotaoadapter.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import br.com.drsolutions.duvidabotaoadapter.Fragment.ClientesFragment;
import br.com.drsolutions.duvidabotaoadapter.Fragment.InicialFragment;
import br.com.drsolutions.duvidabotaoadapter.Interface.XmlClickableClientes;
import br.com.drsolutions.duvidabotaoadapter.Interface.XmlClickableInicial;
import br.com.drsolutions.duvidabotaoadapter.R;
/**
* Classe inicial do sistema
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public class MainActivity extends AppCompatActivity {
// Fragmentos
XmlClickableInicial inicialFragment;
XmlClickableClientes clientesFragment;
private TextView textCliente;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Fragmento (tela) inicial
inicialFragment = new InicialFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.container_conteudo, (Fragment) inicialFragment);
fragmentTransaction.commit();
// Fragmento Clientes
clientesFragment = new ClientesFragment();
}
/**
* Alterar o Cliente Selecionado
* @param nome sendo o nome do Cliente
*/
public void alterarCliente(String nome) {
inicialFragment.alterarCliente(nome);
}
/**
* Clique no botão 'Selecionar' no InicialFragment
* @param v sendo a view
*/
public void btnInicialSelecionarClickMethod(View v) {
clientesFragment = new ClientesFragment();
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.container_conteudo, (Fragment) clientesFragment);
fragmentTransaction.commit();
}
}
package br.com.drsolutions.duvidabotaoadapter.Adapter;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import br.com.drsolutions.duvidabotaoadapter.Model.Cliente;
import br.com.drsolutions.duvidabotaoadapter.R;
import static br.com.drsolutions.duvidabotaoadapter.R.layout.adapter_cliente;
/**
* Adapter de Clientes
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public class AdapterClientes extends RecyclerView.Adapter<AdapterClientes.MyViewHolder> {
List<Cliente> listaClientes;
public AdapterClientes(List<Cliente> listaClientes) {
this.listaClientes = listaClientes;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemLista = LayoutInflater.from(parent.getContext()).inflate(adapter_cliente,
parent, false);
return new MyViewHolder(itemLista);
}
@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
Cliente cliente = listaClientes.get(position);
holder.nome.setText(cliente.getNome());
holder.email.setText(cliente.getEmail());
/**
* Listener colocado no botão 'Selecione' que aparece para cada Cliente
*/
holder.btnSelecione.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(),
"Cliente Selecionado: " + holder.nome.getText().toString(),
Toast.LENGTH_LONG).show();
/**
* ****************************************
* ****************************************
*
* COMO EXECUTAR O MÉTODO
*
* public void alterarCliente(String nome)
*
* QUE ESTÁ NA MainActivity?
*
* ****************************************
* ****************************************
*/
}
});
}
@Override
public int getItemCount() {
return listaClientes.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView nome;
TextView email;
Button btnSelecione;
public MyViewHolder(View itemView) {
super(itemView);
nome = itemView.findViewById(R.id.textNomeCliente);
email = itemView.findViewById(R.id.textEmailCliente);
btnSelecione = itemView.findViewById(R.id.buttonSelecione);
}
}
}
package br.com.drsolutions.duvidabotaoadapter.Fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.List;
import br.com.drsolutions.duvidabotaoadapter.Adapter.AdapterClientes;
import br.com.drsolutions.duvidabotaoadapter.Interface.XmlClickableClientes;
import br.com.drsolutions.duvidabotaoadapter.Model.Cliente;
import br.com.drsolutions.duvidabotaoadapter.R;
/**
* Fragment para gerar a tela de Clientes do Sistema
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public class ClientesFragment extends Fragment implements XmlClickableClientes {
private RecyclerView recyclerClientes;
private List<Cliente> listaClientes = new ArrayList<>();
public ClientesFragment() {
// 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_clientes, container, false);
recyclerClientes = view.findViewById(R.id.recyclerClientes);
// Listagem de Clientes
this.criarClientes();
// Configurar o Adaptador (adapter)
AdapterClientes adapterMeusClientes = new AdapterClientes(listaClientes);
// Configurar o RecyclerView
// RecyclerView terá um tamanho fixo - Recomendação para melhorar a performance
recyclerClientes.setHasFixedSize(true);
// Colocar um traço de divisão entre cada cliente
recyclerClientes.addItemDecoration(new DividerItemDecoration(view.getContext(),
LinearLayout.VERTICAL));
// Utilizar o LinearLayout
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(view.getContext());
recyclerClientes.setLayoutManager(layoutManager);
// Definir a adaptador
recyclerClientes.setAdapter(adapterMeusClientes);
return view;
}
@Override
public void btnClientesSelecionarClickMethod(View v) {
// Não está sendo utilizado, pois o botão está no Adapter
}
/**
* Criar lista temporária de clientes para testar esta tela
*/
public void criarClientes() {
Cliente cliente = new Cliente();
cliente.setNome("Ana Maria Almeida");
cliente.setEmail("ana.maria@exemplo.com");
listaClientes.add(cliente);
cliente = new Cliente();
cliente.setNome("Bruna Lobato Herrero");
cliente.setEmail("bruna.lobato@exemplo.com");
listaClientes.add(cliente);
cliente = new Cliente();
cliente.setNome("Carolina Degani Barbosa");
cliente.setEmail("carol.degani@exemplo.com");
listaClientes.add(cliente);
}
}
package br.com.drsolutions.duvidabotaoadapter.Fragment;
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.TextView;
import android.widget.Toast;
import br.com.drsolutions.duvidabotaoadapter.Interface.XmlClickableInicial;
import br.com.drsolutions.duvidabotaoadapter.R;
/**
* Fragment para gerar a Tela Inicial do Sistema
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public class InicialFragment extends Fragment implements XmlClickableInicial {
TextView textCliente;
public InicialFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_inicial, container, false);
textCliente = view.findViewById(R.id.textCliente);
return view;
}
@Override
public void btnInicialSelecionarClickMethod(View v) {
// Código em MainActivity
}
/**
* Alterar o Cliente Selecionado
* @param nome sendo o nome do Cliente
*/
@Override
public void alterarCliente(String nome) {
if (nome.length() > 0)
textCliente.setText(nome);
else
Toast.makeText(getContext(), "Nome do Cliente não enviado",
Toast.LENGTH_SHORT).show();
}
}
package br.com.drsolutions.duvidabotaoadapter.Interface;
import android.view.View;
/**
* Interface utilizada no ClientesFragment
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public interface XmlClickableClientes {
void btnClientesSelecionarClickMethod(View v);
}
package br.com.drsolutions.duvidabotaoadapter.Interface;
import android.view.View;
/**
* Interface utilizada no InicialFragment
*
* @author Diego Mendes Rodrigues
* @author drSolutions Tecnologia em Informática
* @see <a href='https://www.drsolutions.com.br'>https://www.drsolutions.com.br</a>
* @version 1.0
*/
public interface XmlClickableInicial {
void btnInicialSelecionarClickMethod(View v);
void alterarCliente(String nome);
}
<?xml version="1.0" encoding="utf-8"?>
<!--
@author Diego Mendes Rodrigues
@author drSolutions Tecnologia em Informática
@see https://www.drsolutions.com.br
@version 1.0
-->
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Activity.MainActivity">
<FrameLayout
android:id="@+id/container_conteudo"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--
@author Diego Mendes Rodrigues
@author drSolutions Tecnologia em Informática
@see https://www.drsolutions.com.br
@version 1.0
-->
<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="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textNomeCliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="start"
android:text="@string/txt_adap_clientes_nome"
android:textSize="18sp" />
<TextView
android:id="@+id/textEmailCliente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="start"
android:text="@string/txt_adap_clientes_email"
android:textSize="18sp" />
<Button
android:id="@+id/buttonSelecione"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="24dp"
android:text="@string/txt_adap_clientes_selecione"
android:textAllCaps="false" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--
@author Diego Mendes Rodrigues
@author drSolutions Tecnologia em Informática
@see https://www.drsolutions.com.br
@version 1.0
-->
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment.ClientesFragment">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/txt_clientes_clientes"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerClientes"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<!--
@author Diego Mendes Rodrigues
@author drSolutions Tecnologia em Informática
@see https://www.drsolutions.com.br
@version 1.0
-->
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Fragment.InicialFragment">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/txt_inicial_cliente_selecionado"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textCliente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:text="@string/txt_inicial_nao_selecionado"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<Button
android:id="@+id/buttonSelecionar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:onClick="btnInicialSelecionarClickMethod"
android:text="@string/txt_inicial_selecionar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textCliente" />
</android.support.constraint.ConstraintLayout>
<resources>
<string name="app_name">Dúvida - Botão no Adapter</string>
<!-- InicialFragment -->
<string name="txt_inicial_cliente_selecionado">Cliente Selecionado:</string>
<string name="txt_inicial_nao_selecionado">Nenhum cliente selecionado</string>
<string name="txt_inicial_selecionar">Selecionar</string>
<!-- ClientesFragment -->
<string name="txt_clientes_clientes">Clientes</string>
<!-- adapter_clientes -->
<string name="txt_adap_clientes_nome">Nome</string>
<string name="txt_adap_clientes_email">E-mail</string>
<string name="txt_adap_clientes_selecione">Selecione</string>
</resources>
Enviar mensagem ao usuário trabalhando com as opções do php.ini
Meu Fork do Plugin de Integração do CVS para o KDevelop
Compartilhando a tela do Computador no Celular via Deskreen
Como Configurar um Túnel SSH Reverso para Acessar Sua Máquina Local a Partir de uma Máquina Remota
Configuração para desligamento automatizado de Computadores em um Ambiente Comercial
Compartilhamento de Rede com samba em modo Público/Anônimo de forma simples, rápido e fácil
Cups: Mapear/listar todas as impressoras de outro Servidor CUPS de forma rápida e fácil
Criando uma VPC na AWS via CLI
É possível baixar o dicionário pt-br para /usr/share/dict no Linux Min... (1)
Arch Linux - Guia para Iniciantes (0)