Android 自定义光标适配器(获取位置)
我想为我的图像视图设置touchable,以及如何在列表视图中获得每行图像视图的位置Android 自定义光标适配器(获取位置),android,custom-cursor,Android,Custom Cursor,我想为我的图像视图设置touchable,以及如何在列表视图中获得每行图像视图的位置 public View newView(Context context, Cursor cursor, ViewGroup parent) { // when the view will be created for first time, // we need to tell the adapters, how each item will look L
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// when the view will be created for first time,
// we need to tell the adapters, how each item will look
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.list_shipments, parent, false);
return retView;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
}
}
调用
newView
或bindView
时,光标已定位在准确的行上。您只需设置onClick或OnTouch侦听器:
@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View retView = inflater.inflate(R.layout.list_shipments, parent, false);
ViewHolder holder = new ViewHolder(view);
view.setTag(holder);
return view;
}
@Override
public void bindView(View view, final Context context, Cursor cursor)
{
ViewHolder holder = (ViewHolder) view.getTag();
holder.image.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
// do something
}
}
ViewHolder的一些代码
:
public static class ViewHolder
{
private ImageView image;
public ViewHolder(View view)
{
image = (ImageView) view.findViewById(R.id.image);
}
}
@阿尼尔
这里是我的View.OnClickListener中的代码
holder.img.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
String abc = holder.tv1.getText().toString();
String def = holder.tv2.getText().toString();
System.out.println(abc + def);
String lat = abc;
String lng = def;
String[] countryValues = getResources().getStringArray(R.array.str_array_country_values);
String country = SettingsActivity.getPreferencesStringValue(CursorAdapterActivity.this,
SettingsActivity.KEY_COUNTRY_CODE, "");
String uri = "";
if (country.equals(countryValues[0])){
uri = "http://api.map.baidu.com/marker?location=" + lat + "," + lng + "&zoom=15&title= &content= &output=html";
}
else{
uri = "https://maps.google.com/maps?q=" + lat + "," + lng + "&z=15";
}
startActivity(new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri)));
}
});
谢谢!这个命令真的节省了很多时间,而且我可以很容易地理解算法:)对不起,在view.onClickListener中可以使用startacitivity或SettingActivity.getPreferencesStringValue吗?因为我想通过这个view.imageview.onclick链接到其他接口:(这不是一个活动(只是一个类)使用context.startActivity…
。并为另一个问题问另一个问题)public void bindView(视图视图,最终上下文,光标)