我希望在用户将视图滑动到呼叫电话号码时在“有意图的回收视图”中获取电话号码。
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("tel:"+getnumber));
startActivity(intent);
Rabeta.Class
package com.recycleview;
public class Rabeta {
private String Name;
private int image;
private String Number;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public int getImage() {
return image;
}
public void setImage(int image) {
this.image = image;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public Rabeta(String name, int image, String number) {
Name = name;
this.image = image;
Number = number;
}
}
主要活动.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recview = findViewById(R.id.recyclerv_view);
final Rabeta[] rabetas = new Rabeta[]{
new Rabeta("Zunaid", android.R.drawable.ic_menu_report_image, "017589879997"),
new Rabeta("L", android.R.drawable.ic_menu_report_image, "019589879997"),
new Rabeta("Z", android.R.drawable.ic_menu_report_image, "018589879997"),
new Rabeta("B", android.R.drawable.ic_menu_report_image, "011589879997"),
new Rabeta("A", android.R.drawable.ic_menu_report_image, "012589879997"),
new Rabeta("S", android.R.drawable.ic_menu_report_image, "015589879997"),
};
final SwipeToAction swipeToAction = new SwipeToAction(recview, new SwipeToAction.SwipeListener() {
@Override
public boolean swipeLeft(Object itemData) {
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("tel:"+getnumber));
startActivity(intent);
return true;
}
@Override
public boolean swipeRight(Object itemData) {
Intent intent=new Intent(Intent.ACTION_VIEW,Uri.parse("sms:017-9579-00551"));
startActivity(intent);
return true;
}
@Override
public void onClick(Object itemData) {
}
@Override
public void onLongClick(Object itemData) {
}
});
recview.setAdapter (new RecyclerAdapter(rabetas));
recview.setLayoutManager(new LinearLayoutManager(this));
recview.setHasFixedSize(true);
};
}
RecyclerAdapter.java
public class RecyclerAdapter extends RecyclerView.Adapter <RecyclerAdapter.ViewHolder> {
Rabeta[] name;
public RecyclerAdapter(Rabeta[] name) {
this.name = name;
}
@NonNull
@Override
public RecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewtype) {
View view = (View) LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_listitem,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RecyclerAdapter.ViewHolder viewHolder, int position) {
final Rabeta rabeta = name [position];
viewHolder.name.setText(rabeta.getName());
viewHolder.number.setText(rabeta.getNumber());
viewHolder.imageView.setImageResource(rabeta.getImage());
}
@Override
public int getItemCount() {
return name.length;
}
public class ViewHolder extends SwipeToAction.ViewHolder {
TextView name;
ImageView imageView;
TextView number;
RelativeLayout relativeLayout;
public ViewHolder(@NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.title);
imageView = itemView.findViewById(R.id.image);
}
}
}