我有一个列表视图,这个列表里面,当点击它的一个项目,它会显示内对话框中的自定义列表
在对话框中显示出来,但其只显示对话框的标题
这是我的code
案例R.id.CommentNumOfLike:
dbobj =新的数据库处理器(的getContext());
Items1 = dbobj.select_HowComment();
dbobj.CloseDataBase();
Collections.reverse(Items1);
X =(整数)view.getTag();
Log.v(价值,X +);
。TARGET = Items1.get(X).getCommentId()的toString();
CommentEvents R =新CommentEvents();
r.execute(USER_ID,secret_id,表,目标);
最后一个对话框对话框=新的对话框(的getContext());
dialog.setContentView(R.layout.likers_list);
dialog.setTitle(likers清单);
dialog.setCanceledOnTouchOutside(真正的);
dbobj =新的数据库处理器(的getContext());
likeItems = dbobj.select_HowlikeComment();
dbobj.CloseDataBase();
ListView控件列表=(ListView控件)dialog.findViewById(R.id.ListLikersList);
LikersCustomeAdapter适配器=新LikersCustomeAdapter(的getContext(),R.layout.likerscustomelist,likeItems);
list.setAdapter(适配器);
dialog.show();
打破;
这是我的适配器
公共类LikersCustomeAdapter扩展ArrayAdapter< LikersComment> {
上下文语境;
名单< LikersComment>项目;
点阵位图;
字符串imageUser =;
字符串filePath_Image =/图片/讨伐异教徒/ joj /;
公共LikersCustomeAdapter(上下文的背景下,INT textViewResourceId,
名单< LikersComment>对象){
超(背景下,textViewResourceId,对象);
// TODO自动生成构造函数存根
this.context =背景;
}
公共查看getView(最终诠释的立场,观点convertView,ViewGroup中父){
Log.d(查看likers表,视图>>>>>>>>);
likerscommentholder H = NULL;
视图V = convertView;
Log.v(项目的getName,items.get(位置).getName());
LayoutInflater VI =(LayoutInflater)上下文
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
如果(V == NULL){
V = vi.inflate(R.layout.likerscustomelist,NULL);
H =新likerscommentholder();
h.likersimg =(ImageView的)v.findViewById(R.id.likersImg);
h.likersname =(TextView中)v.findViewById(R.id.likersName);
v.setTag(H);
} 其他 {
H =(likerscommentholder)v.getTag();
}
imageUser = items.get(位置).getId()+ items.get(位置).getRand();
布尔flag_ImagePath = Methods.checkIfImage_DirExists(filePath_Image
+ imageUser);
如果(flag_ImagePath ==真){
Log.v(flag_ImagePath,将String.valueOf(flag_ImagePath));
位= Methods.displayBitmapImage(imageUser);
h.likersimg.setImageBitmap(位);
}
h.likersname.setText(items.get(位置).getName());
返回伏;
}
}
类likerscommentholder {
ImageView的likersimg;
TextView的likersname;
}
这是列表视图
likers_list.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
<的ListView
机器人:ID =@ + ID / ListLikersList
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT>
< / ListView控件>
这是自定义布局
likerscustomelist.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
< ImageView的
机器人:ID =@ + ID / likersImg
机器人:layout_width =65dp
机器人:layout_height =65dp
机器人:layout_alignParentLeft =真
机器人:layout_alignParentTop =真
机器人:SRC =@可绘制/ ic_launcher/>
<的TextView
机器人:ID =@ + ID / likersName
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:layout_marginLeft =16DP
机器人:layout_marginTop =19dp
机器人:layout_toRightOf =@ + ID / likersImg
机器人:文本=中文字
机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>
< / RelativeLayout的>
< / LinearLayout中>
解决方案
您需要使用 AlertDialog.Builder
-
请参考这个 - 文档
编辑 -
新AlertDialog.Builder(MyActivity.this)
.setAdapter(yourListAdapter,新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
// TODO - $ c当列表项被点击(INT这 - 是参数,让你点击项目的索引)$ C
}
})
.setPositiveButton(好,新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
}
})
.setNegativeButton(取消,新DialogInterface.OnClickListener(){
@覆盖
公共无效的onClick(DialogInterface对话,诠释它){
}
})
.setTitle(对话框标题)
.setCancelable(假)
。显示();
i have a list view , inside this list when click on an item of it ,it will show a custom list inside a dialog box
the dialog shows up but its only shows the title of the dialog
here is my code
case R.id.CommentNumOfLike:
dbobj = new DataBaseHandler(getContext());
Items1 = dbobj.select_HowComment();
dbobj.CloseDataBase();
Collections.reverse(Items1);
x = (Integer) view.getTag();
Log.v("value", x + "");
target = Items1.get(x).getCommentId().toString();
CommentEvents r = new CommentEvents();
r.execute(user_id, secret_id, table, target);
final Dialog dialog = new Dialog(getContext());
dialog.setContentView(R.layout.likers_list);
dialog.setTitle("List of likers");
dialog.setCanceledOnTouchOutside(true);
dbobj = new DataBaseHandler(getContext());
likeItems=dbobj.select_HowlikeComment();
dbobj.CloseDataBase();
ListView list = (ListView) dialog.findViewById(R.id.ListLikersList);
LikersCustomeAdapter adapter= new LikersCustomeAdapter(getContext(), R.layout.likerscustomelist, likeItems);
list.setAdapter(adapter);
dialog.show();
break;
this is my adapter
public class LikersCustomeAdapter extends ArrayAdapter<LikersComment>{
Context context;
List<LikersComment> items;
Bitmap bitmap;
String imageUser = "";
String filePath_Image = "/Pictures/jehad/joj/";
public LikersCustomeAdapter(Context context, int textViewResourceId,
List<LikersComment> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
this.context=context;
}
public View getView(final int position, View convertView, ViewGroup parent) {
Log.d("View likers List", "View>>>>>>>>");
likerscommentholder h = null;
View v = convertView;
Log.v("items getName", items.get(position).getName());
LayoutInflater vi = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (v == null) {
v = vi.inflate(R.layout.likerscustomelist,null);
h = new likerscommentholder();
h.likersimg=(ImageView)v.findViewById(R.id.likersImg);
h.likersname=(TextView)v.findViewById(R.id.likersName);
v.setTag(h);
} else {
h = (likerscommentholder) v.getTag();
}
imageUser = items.get(position).getId() + items.get(position).getRand();
boolean flag_ImagePath = Methods.checkIfImage_DirExists(filePath_Image
+ imageUser);
if (flag_ImagePath == true) {
Log.v("flag_ImagePath", String.valueOf(flag_ImagePath));
bitmap = Methods.displayBitmapImage(imageUser);
h.likersimg.setImageBitmap(bitmap);
}
h.likersname.setText(items.get(position).getName());
return v;
}
}
class likerscommentholder {
ImageView likersimg;
TextView likersname;
}
this is the list view
likers_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/ListLikersList"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
this is the custom layout
likerscustomelist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/likersImg"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/likersName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="16dp"
android:layout_marginTop="19dp"
android:layout_toRightOf="@+id/likersImg"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</LinearLayout>
解决方案
You need to use AlertDialog.Builder
-
Refer this- Docs
Edit -
new AlertDialog.Builder(MyActivity.this)
.setAdapter(yourListAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//TODO - Code when list item is clicked (int which - is param that gives you the index of clicked item)
}
})
.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setTitle("Dialog Title")
.setCancelable(false)
.show();