从片段内的自定义列表适配器创建警报对话框
create alertdialog from a cutom list adapter which is inside a fragment
我的应用程序有两个片段,可以作为选项卡滑动。第一个片段使用自定义列表适配器在列表视图中显示项目列表。单击列表中的项目时,我想显示一个对话框以输入一些数据。
这是应用程序的快照
这是设置第一个片段的代码
private void setFragOne1() {
String sql = "select admin_email, admin_name, admin_img, admin_contact, admin_status from links";
cr = sdb.rawQuery(sql, null);
try{
linksList = new ArrayList<>();
while(cr.moveToNext()) {
admin_email = cr.getString(0);
admin_name = cr.getString(1);
admin_img = cr.getString(2);
admin_contact = cr.getString(3);
admin_status = Integer.parseInt(cr.getString(4));
linksList.add(new f1_row_model(admin_email, admin_name, admin_img, admin_contact, admin_status));
}
//last item for add new link
linksList.add(new f1_row_model("","Click here to add link","","",-1));
f1adapter = new f1_row_adapter(linksList, getContext());
lv_all_links.setAdapter(f1adapter);
}catch (Exception e){
Log.e("SFO1", e.toString());
}
}
这是在我的适配器中单击列表视图时调用的代码
protected void show_subscribe_form() {
try {
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout;
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
ed_subscription_email = (EditText)
layout.findViewById(R.id.edEmail);
ed_note = (EditText) layout.findViewById(R.id.edNote);
//Building dialog
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setCancelable(false);
builder.setTitle("Enter the Email Address to Link to");
builder.setIcon(ContextCompat.getDrawable(mContext,
R.drawable.linkto));
builder.setPositiveButton("Subscribe", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}catch(Exception e){
Toast.makeText(mContext, "ssf " + e.toString(),
Toast.LENGTH_SHORT).show();
Log.e("ssf",e.toString());
}
}
我在这一行遇到错误
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
错误是"cannot resolve method findViewById(int)"
我这里哪里做错了?
尝试改变
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
到
layout = inflater.inflate(R.layout.subscribe,null);
我的应用程序有两个片段,可以作为选项卡滑动。第一个片段使用自定义列表适配器在列表视图中显示项目列表。单击列表中的项目时,我想显示一个对话框以输入一些数据。
这是应用程序的快照
这是设置第一个片段的代码
private void setFragOne1() {
String sql = "select admin_email, admin_name, admin_img, admin_contact, admin_status from links";
cr = sdb.rawQuery(sql, null);
try{
linksList = new ArrayList<>();
while(cr.moveToNext()) {
admin_email = cr.getString(0);
admin_name = cr.getString(1);
admin_img = cr.getString(2);
admin_contact = cr.getString(3);
admin_status = Integer.parseInt(cr.getString(4));
linksList.add(new f1_row_model(admin_email, admin_name, admin_img, admin_contact, admin_status));
}
//last item for add new link
linksList.add(new f1_row_model("","Click here to add link","","",-1));
f1adapter = new f1_row_adapter(linksList, getContext());
lv_all_links.setAdapter(f1adapter);
}catch (Exception e){
Log.e("SFO1", e.toString());
}
}
这是在我的适配器中单击列表视图时调用的代码
protected void show_subscribe_form() {
try {
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout;
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
ed_subscription_email = (EditText)
layout.findViewById(R.id.edEmail);
ed_note = (EditText) layout.findViewById(R.id.edNote);
//Building dialog
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setCancelable(false);
builder.setTitle("Enter the Email Address to Link to");
builder.setIcon(ContextCompat.getDrawable(mContext,
R.drawable.linkto));
builder.setPositiveButton("Subscribe", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}catch(Exception e){
Toast.makeText(mContext, "ssf " + e.toString(),
Toast.LENGTH_SHORT).show();
Log.e("ssf",e.toString());
}
}
我在这一行遇到错误
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
错误是"cannot resolve method findViewById(int)"
我这里哪里做错了?
尝试改变
layout = inflater.inflate(R.layout.subscribe, (ViewGroup)
findViewById(R.id.root), false);
到
layout = inflater.inflate(R.layout.subscribe,null);