答案 0 :(得分:0)
您可以使用现有的库CarouselPicker
它同时支持图标和文本字段。
答案 1 :(得分:0)
使用如下列表视图创建布局...
<ListView
android:id="@+id/sample_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="DrawableResource/HEXColor"
android:background="DrawableResource/HEXColor"
android:padding="10dp"/>
并根据您的数据类型(如TextView或ImageView)创建一个列表项
我没有添加导入语句...
public class PicData {
public interface setDataSelectedListener{
public void onDataSelected(YourDataType data);
}
List<YourDataType> list;
Context con;
ListView lv;
LayoutInflator lf;
setDataSelectedListener listener;
AlertDialog ad;
public PicData(Context c, List<YourDataType> l,setDataSelectedListener sl){
this.list=l;
this.con=c;
this.listener=sl;
lf=(LayoutInflator)con.getSystemService(Context.LAYOUT_INFLATOR_SERVICE);
View v=lf.inflate(R.layout.your_layout,null);
lv=(ListView)v.findViewById(R.id.sample_list);
lv.setAdapter(new BaseAdapter(){
@Override
public View getView(int pos, View v1, ViewGroup vg){
if(v1==null)v1=lf.inflate(R.layout.item_layout,null);
YourChildView child=v1.findViewById(R.id.child_id);
/*Here you have to set your data like...
child.setText(list.get(pos)); if it is TextView
child.setImageBitmap(list.get(pos)); if it is ImageView
*/
return v1;
}
@Override
public YourDataType getItem(int pos){
return list.get(pos);
}
@Override
public long getItemId(int pos){
return pos;
}
@Override
public int getCount(){
return list.size();
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> av, View v2, int pos1, long ll){
listener.onDataSelected(list.get(pos1);
});
AlertDialog.Builder bd=new AlerDialog.BUilder(con);
bd.setTitle("Pick Data");
bd.setView(v);
ad=bd.create();
}
protected void show(){
ad.show:
}
}
在您的活动中添加如下内容...
GetData gd=new GetData(this,YourDataTypeList,new GetData.setDataSelectedListener(){
@Override
public void onDataSelected(YourDataType data){
//Do your work here...
}
});
您可以根据需要自定义上述代码。