Android 提供onBindViewHolder侦听器警报对话框
有人能帮我吗?我很难让我的AlertDialog显示出来。我正在根据单击的项目创建AlertDialog 如果有人能告诉我如何才能让这个警报对话框正常工作。下面是我的问题截图的链接: 以下是代码:Android 提供onBindViewHolder侦听器警报对话框,android,Android,有人能帮我吗?我很难让我的AlertDialog显示出来。我正在根据单击的项目创建AlertDialog 如果有人能告诉我如何才能让这个警报对话框正常工作。下面是我的问题截图的链接: 以下是代码: package com.mario.restaurantcroatia; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInf
package com.mario.restaurantcroatia;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import java.util.List;
public class LandingRestaurantAdapter extends RecyclerView.Adapter<LandingRestaurantAdapter.RestaurantViewHolder>{
public interface PositionClickListener
{
void itemClicked(int position);
}
private Context context;
private List<LandingRestaurants> restaurantsList;
public LandingRestaurantAdapter(Context context, List<LandingRestaurants> restaurantsList) {
this.context = context;
this.restaurantsList = restaurantsList;
}
@Override
public RestaurantViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from( context );
View view = inflater.inflate( R.layout.landing_items, null );
RestaurantViewHolder holder = new RestaurantViewHolder( view );
return holder;
}
@Override
public void onBindViewHolder(final RestaurantViewHolder holder, final int position) {
LandingRestaurants restaurant = restaurantsList.get( position );
holder.imageView.setImageDrawable( context.getResources().getDrawable( restaurant.getPicture() ) );
//onClickListener for landing page town cards
holder.imageView.setOnClickListener( new View.OnClickListener( ) {
@Override
public void onClick(View view) {
/* LayoutInflater inflater = LayoutInflater.from( context );
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
view = inflater.inflate(R.layout.landing_click_on_town_alert_dialog,null);
ImageView location = (ImageView)view.findViewById( R.id.location );
ImageView currentRestaurant = (ImageView)view.findViewById( R.id.restaurant );
ImageView history = (ImageView)view.findViewById( R.id.history );
ImageView attractions = (ImageView)view.findViewById( R.id.attractions );
mBuilder.setView( view );
AlertDialog dialog = mBuilder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();*/
}
} );
}
@Override
public int getItemCount() {
return restaurantsList.size();
}
class RestaurantViewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
public RestaurantViewHolder(View itemView) {
super( itemView );
imageView = (ImageView)itemView.findViewById( R.id.picture );
}
}
}
package com.mario.restaurantcroatia;
导入android.content.Context;
导入android.support.v7.widget.RecyclerView;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ImageView;
导入java.util.List;
公共类LandingRestaurantAdapter扩展了RecyclerView.Adapter{
公共接口位置ClickListener
{
无效项(int位置);
}
私人语境;
私人名单餐厅名单;
public LandingRestaurantAdapter(上下文上下文,列表restaurantsList){
this.context=上下文;
this.restaurantsList=restaurantsList;
}
@凌驾
公共餐厅ViewHolder onCreateViewHolder(视图组父级,int-viewType){
LayoutFlater充气机=LayoutFlater.from(上下文);
视图=充气机。充气(R.layout.landing_项目,空);
RestaurantViewHolder=新的RestaurantViewHolder(视图);
报税表持有人;
}
@凌驾
BindViewHolder上的公共无效(最终餐厅视图持有人,最终内部位置){
LandingRestaurants=restaurantsList.get(位置);
holder.imageView.setImageDrawable(context.getResources().getDrawable(restaurant.getPicture());
//登录页城镇卡的onClickListener
holder.imageView.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
/*LayoutFlater充气机=LayoutFlater.from(上下文);
final AlertDialog.Builder mBuilder=新建AlertDialog.Builder(上下文);
视图=充气机。充气(右布局。着陆\u单击\u城镇\u警报\u对话框,空);
ImageView位置=(ImageView)view.findViewById(R.id.location);
ImageView currentRestaurant=(ImageView)view.findViewById(R.id.restaurant);
ImageView历史=(ImageView)view.findViewById(R.id.history);
ImageView景点=(ImageView)view.findViewById(R.id.attractions);
mBuilder.setView(视图);
AlertDialog=mBuilder.create();
dialog.getWindow().setBackgroundDrawable(新的ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show()*/
}
} );
}
@凌驾
public int getItemCount(){
return restaurantsList.size();
}
类RestaurantViewHolder扩展了RecyclerView.ViewHolder{
图像视图图像视图;
公共餐厅查看文件夹(查看项目视图){
超级(项目视图);
imageView=(imageView)itemView.findViewById(R.id.picture);
}
}
}
您是否尝试删除透明背景
LayoutInflater inflater = LayoutInflater.from( view.getContext());
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
View viewdialog = inflater.inflate(R.layout.landing_click_on_town_alert_dialog, null, false);
ImageView location = (ImageView)viewdialog.findViewById( R.id.location );
ImageView currentRestaurant = (ImageView)viewdialog .findViewById( R.id.restaurant );
ImageView history = (ImageView)viewdialog.findViewById( R.id.history );
ImageView attractions = (ImageView)viewdialog.findViewById( R.id.attractions );
mBuilder.setView( viewdialog );
AlertDialog dialog = mBuilder.create();
dialog.show();
您是否尝试删除透明背景
LayoutInflater inflater = LayoutInflater.from( view.getContext());
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
View viewdialog = inflater.inflate(R.layout.landing_click_on_town_alert_dialog, null, false);
ImageView location = (ImageView)viewdialog.findViewById( R.id.location );
ImageView currentRestaurant = (ImageView)viewdialog .findViewById( R.id.restaurant );
ImageView history = (ImageView)viewdialog.findViewById( R.id.history );
ImageView attractions = (ImageView)viewdialog.findViewById( R.id.attractions );
mBuilder.setView( viewdialog );
AlertDialog dialog = mBuilder.create();
dialog.show();
这是由于单击方法视图时对象名称与充气机视图不匹配,因此请将“充气机对象名称”视图更改为“对话框视图”,否则
view = inflater.inflate(R.layout.landing_click_on_town_alert_dialog,null);
把它改成likebelow
LayoutInflater inflater = LayoutInflater.from( context );
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
View dialogView = inflater.inflate(R.layout.landing_click_on_town_alert_dialog,null);
ImageView location = (ImageView)dialogView.findViewById( R.id.location );
ImageView currentRestaurant = (ImageView)dialogView.findViewById( R.id.restaurant );
ImageView history = (ImageView)dialogView.findViewById( R.id.history );
ImageView attractions = (ImageView)dialogView.findViewById( R.id.attractions );
mBuilder.setView( dialogView);
AlertDialog dialog = mBuilder.create();
dialog.show();
这是由于单击方法视图时对象名称与充气机视图不匹配,因此请将“充气机对象名称”视图更改为“对话框视图”,否则
view = inflater.inflate(R.layout.landing_click_on_town_alert_dialog,null);
把它改成likebelow
LayoutInflater inflater = LayoutInflater.from( context );
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(context);
View dialogView = inflater.inflate(R.layout.landing_click_on_town_alert_dialog,null);
ImageView location = (ImageView)dialogView.findViewById( R.id.location );
ImageView currentRestaurant = (ImageView)dialogView.findViewById( R.id.restaurant );
ImageView history = (ImageView)dialogView.findViewById( R.id.history );
ImageView attractions = (ImageView)dialogView.findViewById( R.id.attractions );
mBuilder.setView( dialogView);
AlertDialog dialog = mBuilder.create();
dialog.show();
还是没什么。屏幕截图它总是说我的膨胀行是错误的。视图=充气机…还是什么都没有。甚至可以调用警报对话框在充气机类中充气吗?你的日志猫在说什么?请上传文本而不是图像,我看不出你的xml布局有问题,为什么充气失败,直到什么都没有。屏幕截图它总是说我的膨胀行是错误的。视图=充气机…还是什么都没有。甚至可以调用警报对话框在充气机类中充气吗?您的日志猫在说什么?请上传文本而不是图像,我看不出您的xml布局存在问题,这就是充气失败的原因。这里有一个屏幕截图。如果字体太小,我会把它们弄大。好的,我可以显示用于登录的xml文件吗?单击“城镇警报”对话框?好的,尝试删除第一行布局背景可能是问题的原因。只需删除并尝试它
ractangle\u background\u alert\u dialog\u landing\u page
。这就是问题所在。我的背景是drawable(v24),非常突出。创建一个新的,它的工作。非常感谢你,我试了一整天,现在我可以继续我的项目了。你能告诉我v24代表什么吗?这是一个截图。如果字体太小,我会把它们弄大。好的,我可以显示用于登录的xml文件吗?单击“城镇警报”对话框?好的,尝试删除第一行布局背景可能是问题的原因。只需删除并尝试它ractangle\u background\u alert\u dialog\u landing\u page
。这就是问题所在。我的背景是drawable(v24),非常突出。创建一个新的,它的工作。非常感谢你,我试了一整天,现在我可以继续我的项目了。你能告诉我v24代表什么吗?