Tenho um Fragment e nele tem um botão. Ao clicar neste botão queria executar o evento de arrastar o dedo da direita para a esquerda.
Segue abaixo o código do meu fragmento:
public class MyFragment extends Fragment {
private Context context;
private LayoutInflater layoutInflater;
private ImageView proximo;
private ImageView anterior;
private static Promocao[] promocoes;
private MainActivity mainActivity;
public static Fragment newInstance(MainActivity context, int pos, float scale, Promocao[] promocaoParametro) {
Bundle b = new Bundle();
b.putInt("pos", pos);
b.putFloat("scale", scale);
promocoes=promocaoParametro;
Log.i(TAG, "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
Log.i(TAG, "newInstance: pos ---> "+pos);
Log.i(TAG, "newInstance: scale ---> "+scale);
Log.i(TAG, "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[");
return Fragment.instantiate(context, MyFragment.class.getName(), b);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
LinearLayout view = (LinearLayout)
inflater.inflate(R.layout.mf, container, false);
String valordesconto = "";
SpannableStringBuilder valorDeTextoEditado;
TextView titulo = (TextView) view.findViewById(R.id.titulo);
TextView informacao = (TextView) view.findViewById(R.id.informacao);
TextView bairro = (TextView) view.findViewById(R.id.bairro);
TextView valorDe = (TextView) view.findViewById(R.id.valorDe);
TextView valorPara = (TextView) view.findViewById(R.id.valorPara);
TextView resumoOferta = (TextView) view.findViewById(R.id.resumoOferta);
ImageView imageCliente = (ImageView) view.findViewById(R.id.imageCliente);
ImageView imagemPromocao = (ImageView) view.findViewById(R.id.imagemPromocao);
LinearLayout fundoLayout = (LinearLayout) view.findViewById(R.id.fundoLayout);
final int position = this.getArguments().getInt("pos");
if(this.promocoes[position].vlreal > 0){
String textoDe ="R$ ";
String valorDeTexto = String.format("%.2f",this.promocoes[position].vlreal);
StrikethroughSpan strikethroughSpan = new StrikethroughSpan();
SpannableStringBuilder ssb = new SpannableStringBuilder(textoDe);
ssb.append(valorDeTexto);
ssb.setSpan(
strikethroughSpan,
ssb.length() - valorDeTexto.length(),
ssb.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
valorDeTextoEditado = ssb;
double valorcalc = this.promocoes[position].vlreal - (this.promocoes[position].vlreal * this.promocoes[position].desconto / 100);
valordesconto = "R$ "+String.format("%.2f",valorcalc);
}else{
valorDeTextoEditado = SpannableStringBuilder.valueOf("");
valordesconto = String.valueOf(this.promocoes[position].desconto) + "%";
valorDe.setVisibility(View.INVISIBLE);
valorPara.setTextSize(200);
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) valorPara.getLayoutParams();
ViewGroup.LayoutParams paramsde = (ViewGroup.LayoutParams) valorDe.getLayoutParams();
params.height = 250;
valorPara.setLayoutParams(params);
paramsde.height = 1;
valorDe.setLayoutParams(paramsde);
}
BitmapDrawable background = new BitmapDrawable(this.promocoes[position].imagemByte);
fundoLayout.setBackgroundDrawable(background);
fundoLayout.getBackground().setAlpha(32);
titulo.setText(this.promocoes[position].titulo);
informacao.setText(this.promocoes[position].informacao);
bairro.setText(this.promocoes[position].bairro);
valorDe.setText(valorDeTextoEditado, TextView.BufferType.EDITABLE);
valorPara.setText(valordesconto);
resumoOferta.setText(this.promocoes[position].resumooferta);
imageCliente.setImageBitmap(this.promocoes[position].logoByte);
imagemPromocao.setImageBitmap(this.promocoes[position].imagemByte);
Button b = (Button) view.findViewById(R.id.btnComprar);
proximo = (ImageView) view.findViewById(R.id.btn_proximo);
anterior = (ImageView) view.findViewById(R.id.btn_voltar);
final ViewPager viewPager = (ViewPager)getActivity().findViewById(R.id.myviewpager);
mainActivity = new MainActivity();
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayList<String> ar = new ArrayList<String>();
ar.add(String.valueOf(promocoes[position].idpromocao));
Intent telefone = new Intent(v.getContext(),Telefone.class );
telefone.putStringArrayListExtra("list",ar);
v.getContext().startActivity(telefone);
//Log.i(txtTitulo, txtTitulo);
}
});
proximo.setOnClickListener(new View.OnClickListener(){
public void onClick(View v ){
----- Aqui da direta para a esquerda
}
});
anterior.setOnClickListener(new View.OnClickListener(){
public void onClick(View v ){
----- Aqui da esquerda para a direta
}
});
MyLinearLayout root = (MyLinearLayout) view.findViewById(R.id.root);
float scale = this.getArguments().getFloat("scale");
root.setScaleBoth(scale);
return view;
}
}