Listview项目上的工具提示单击列表器不起作用
此库添加我的项目 编译'com.github.douglasjunior:android-simple-tooltip:0.2.0'
final SimpleTooltip tooltip = new SimpleTooltip.Builder(v.getContext())
.anchorView(v)
.text("Results")
.dismissOnOutsideTouch(true)
.dismissOnInsideTouch(false)
.contentView(R.layout.tooltip,R.id.tv_result_header)
.textColor(getResources().getColor(R.color.green))
.gravity(Gravity.BOTTOM)
.build();
tooltip.show();
ArrayList<Result_ModelList> Result_list = new ArrayList<Result_ModelList>();
Listview lv=(Listview)tooltip.findViewById(R.id.lv);
Result_list.add(new Result_ModelList("Alphabetically"));
Result_list.add(new Result_ModelList("By Code"));
Result_list.add(new Result_ModelList("Last created"));
Result_Adapter adapter = new Sort_Result_Adapter(getApplicationContext(), R.layout.raw_result,Result_list);
lv.setAdapter(adapter);
//**Do not work**
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "do not work" , Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:1)
您是否看到了Usage部分?
Listview lv=(Listview)tooltip.findViewById(R.id.lv);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
new SimpleTooltip.Builder(this)
.anchorView(view)
.text("Something")
.gravity(Gravity.END)
.animated(true)
.transparentOverlay(false)
.build()
.show();
}
});
如果要在ListView上的特定项目上显示它,您可以使用
View v=lv.getChildAt(position);
并将其用作锚视图
anchorView(v)
在第一个项目上显示它:
ArrayList<Result_ModelList> Result_list = new ArrayList<Result_ModelList>();
Listview lv=(Listview)tooltip.findViewById(R.id.lv);
Result_list.add(new
Result_ModelList("Alphabetically"));
Result_list.add(new Result_ModelList("By Code"));
Result_list.add(new Result_ModelList("Last created"));
Result_Adapter adapter = new Sort_Result_Adapter(getApplicationContext(), R.layout.raw_result,Result_list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "do not work" , Toast.LENGTH_SHORT).show();
}
});
View view=lv.getChildAt(0);
SimpleTooltip tooltip = new SimpleTooltip.Builder(v.getContext())
.anchorView(view) //if you want to display on whole listview do .anchorView(lv)
.text("Results")
.dismissOnOutsideTouch(true)
.dismissOnInsideTouch(false)
.contentView(R.layout.tooltip,R.id.tv_result_header)
.textColor(getResources().getColor(R.color.green))
.gravity(Gravity.BOTTOM)
.build();
tooltip.show();