- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
View 持有者不再创建重复项,尽管它有时会返回不正确的位置。下面的控制台输出以及当前代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Text;
using System.Net;
using System.Collections.Specialized;
namespace MyMentor
{
public class dashboardAdapter : BaseAdapter<DashboardLINQ>
{
List<DashboardLINQ> items;
Activity context;
int realpos;
public dashboardAdapter(Activity context, List<DashboardLINQ> items)
: base()
{
this.context = context;
this.items = items;
}
public override long GetItemId(int position)
{
return position;
}
public override DashboardLINQ this[int position]
{
get { return items[position]; }
}
public override int Count
{
get { return items.Count; }
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
ServiceViewHolder holder = null;
Console.WriteLine ("View No If: "+position);
realpos = position;
View view = convertView;
if (view == null) {
Console.WriteLine ("View == Null: "+position);
realpos = position;
holder = new ServiceViewHolder ();
view = LayoutInflater.From (context).Inflate (Resource.Layout.dashboardItemLayout, null, false);
holder.like = view.FindViewById<ImageButton> (Resource.Id.button1);
holder.comment = view.FindViewById<ImageButton> (Resource.Id.button2);
holder.share = view.FindViewById<ImageButton> (Resource.Id.button3);
holder.usrname = view.FindViewById<TextView> (Resource.Id.textView1);
holder.prof = view.FindViewById<ImageView> (Resource.Id.imageView1);
holder.like.Click += (sender, e) => {
WebClient client = new WebClient ();
Uri uri = new Uri ("url");
NameValueCollection parameters = new NameValueCollection ();
parameters.Add ("UID", items [position].MID);
parameters.Add ("PID", items [position].ID);
client.UploadValuesAsync (uri, parameters);
};
holder.share.Click += (sender, e) => {
int MaxLength = 150;
var name = Html.FromHtml (items [position].pDesc).ToString ();
if (name.Length > MaxLength) {
name = name.Substring (0, MaxLength) + "... My Mentor";
}
var myIntent = new Intent (Android.Content.Intent.ActionSend);
myIntent.PutExtra (Intent.ExtraText, name);
myIntent.SetType ("text/plain");
this.context.StartActivity (Intent.CreateChooser (myIntent, "Choose an App"));
};
holder.usrname.Click += (sender, e) => {
// Bundle fragBundle = new Bundle ();
// fragBundle.PutString ("image", items [position].uPicLocal);
// fragBundle.PutString ("name", items [position].uFullName);
// var transaction = this.context.FragmentManager.BeginTransaction ();
// var dialogimgview = new DialogImageView ();
// dialogimgview.Arguments = fragBundle;
// transaction.AddToBackStack (null);
// dialogimgview.Show (transaction, "Dialog_Fragment" + position);
};
holder.prof.Click += (sender, e) => {
Console.WriteLine ("Realpos: "+realpos+" Position: "+position);
};
view.Tag = holder;
} else {
holder = view.Tag as ServiceViewHolder;
Console.WriteLine ("View Not Null: "+position);
}
ImageView prof = view.FindViewById<ImageView>(Resource.Id.imageView1);
Koush.UrlImageViewHelper.SetUrlDrawable (prof, "url"+items [position].uPicLocal);
TextView usrname = view.FindViewById<TextView> (Resource.Id.textView1);
usrname.Text = items [position].uFullName;
TextView date = view.FindViewById<TextView> (Resource.Id.textView2);
date.Text = items [position].pDate;
ImageView imagen = view.FindViewById<ImageView>(Resource.Id.imageView2);
Koush.UrlImageViewHelper.SetUrlDrawable (imagen, "http://www.mymentor.org.za/"+items [position].pImage);
TextView desc = view.FindViewById<TextView> (Resource.Id.textView3);
desc.Text = Html.FromHtml (items [position].pDesc).ToString();
TextView comlike = view.FindViewById<TextView> (Resource.Id.textView4);
comlike.Text = "Likes: "+items [position].likecnumrows+" Comments: "+items [position].commentscnumrows;
return view;
}
void Prof_Click (object sender, EventArgs e)
{
Toast.MakeText(context, "Position: "+realpos, ToastLength.Long).Show();
}
public class ServiceViewHolder : Java.Lang.Object
{
public ImageButton like { get; set; }
public ImageButton comment { get; set; }
public ImageButton share { get; set; }
public ImageView prof { get; set; }
public TextView usrname { get; set; }
}
}
}
下面是控制台输出,向您展示我一直在运行的测试
下面有很多控制台数据所以重点应该放在-查看否-View == Null-Realpos-位置
有需要可以联系我
View No If: 0
View == Null: 0
[art] JNI RegisterNativeMethods: attempt to register 0 native methods for md5c2cbda97c60838cc1822f8363c96ec60.dashboardAdapter_ServiceViewHolder
View No If: 1
View == Null: 1
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isShipBuild true
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isShipBuild true
[System.out] (HTTPLog)-Thread-43421-535359947: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
[System.out] (HTTPLog)-Thread-43421-535359947: SMARTBONDING_FEATURE_ENABLED is true
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Thread-43420-520578202: SmartBonding Enabling is false, SHIP_BUILD is true, log to file is false, DBG is false
[System.out] (HTTPLog)-Thread-43420-520578202: SMARTBONDING_FEATURE_ENABLED is true
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
View No If: 2
View == Null: 2
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[ListView] change accessibility focus position = 0
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 2 Position: 0
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 2 Position: 1
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 2
View Not Null: 2
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 2 Position: 2
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 3
View Not Null: 3
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 3 Position: 0
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 4
View Not Null: 4
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 4 Position: 2
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 2
View Not Null: 2
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 1
View Not Null: 1
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 1 Position: 2
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 0
View Not Null: 0
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 0 Position: 1
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 2
View Not Null: 2
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 3
View Not Null: 3
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 4
View Not Null: 4
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
Realpos: 4 Position: 2
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 2
View Not Null: 2
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] KnoxVpnUidStorageknoxVpnSupported API value returned is false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 1
View Not Null: 1
[ViewRootImpl] ViewPostImeInputStage ACTION_DOWN
View No If: 0
View Not Null: 0
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[System.out] (HTTPLog)-Static: isSBSettingEnabled false
[skia] --- SkImageDecoder::Factory returned null
[skia] --- SkImageDecoder::Factory returned null
最佳答案
现在我明白你的意思了!这发生,因为我们重用了行(是的,保留您的观点是一件好事,不要一次又一次地重新创建)。所以这部分代码有问题:
if (view == null)
要解决这个问题,你必须删除这个代码块( View 为空),然后就可以了,但是你会损失一些性能!(不要以为你有1000个列表项:),因为没有此后置条件方法 GetView() 将始终重绘当前可见的每个 ROW。
所以在你的情况下,我认为这是可以做到的。
让我们试试我的示例,看看相同的东西(使用 Toast):
Main.axml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/editText1" />
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="460dp"
android:id="@+id/lst"
android:layout_marginTop="50dp" />
<Button
android:text="Button"
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/Test"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>
主要 Activity
[Activity(Label = "TestStuff", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Window.SetSoftInputMode(SoftInput.AdjustNothing | SoftInput.AdjustPan);
ListView lst = FindViewById<ListView>(Resource.Id.lst);
Button btn = FindViewById<Button>(Resource.Id.Test);
List<string> Data = new List<string>();
Data.Add("Prosto GG 1");
Data.Add("Prosto GG 2");
Data.Add("Prosto GG 3");
Data.Add("Prosto GG 4");
Data.Add("Prosto GG 5");
Data.Add("Prosto GG 6");
Data.Add("Prosto GG 7");
Data.Add("Prosto GG 8");
Data.Add("Prosto GG 9");
Data.Add("Prosto GG 10");
Data.Add("Prosto GG 11");
CustomAdapter cst = new CustomAdapter(Data, this);
lst.Adapter = cst;
btn.Click += (sender, e) =>
{
Data.Add("ne prosto");
cst.NotifyDataSetChanged();
};
}
}
最后,我们的新 CustomAdapter(没有代码块,其中 View == null)
class CustomAdapter: BaseAdapter<string>
{
List<string> _Items;
Context _context;
public CustomAdapter(List<string> Items,Context context)
{
this._Items = Items;
this._context = context;
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
ServiceViewHolder holder = null;
var view = convertView;
holder = new ServiceViewHolder();
view = LayoutInflater.From(_context).Inflate(Resource.Layout.ListItem, null);
holder.Txt = view.FindViewById<TextView>(Resource.Id.txt);
holder.PushME = view.FindViewById<Button>(Resource.Id.Push);
holder.PushME.Click += (sender, e) =>
{
Toast.MakeText (_context, _Items [position] + " SHOWED", ToastLength.Short).Show ();
//holder.Txt.Text = holder.Txt.Text + "Izmenen najatiem" + position + " poziitii";
}
holder.Txt.Text = _Items[position];
return view;
}
public override int Count
{
get
{
return _Items.Count;
}
}
public override string this[int index]
{
get
{
return _Items[index];
}
}
#endregion
}
public class ServiceViewHolder : Java.Lang.Object
{
public Button PushME { get; set; }
public TextView Txt { get; set; }
}
这样吧!
享受!
PS 另外我想说的是,要注意大尺寸数据(例如列表中的 500-1000 项)。
PPS 但老实说,没有必要将 ListView 与巨大的项目数据一起使用,因为它非常昂贵,为此你可以使用 RecycleView ;)!
关于android - 单击事件的适配器 View 返回不正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33619624/
我正在尝试获取从过去的 startposition/location 到当前移动的 currentposition/location 的距离(以米为单位)。 我确实有工作正常的currentposit
所以我有一堆绝对覆盖的 div。用户通过在叠加层上拖动来创建方形 div。如果您要创建一个 div,然后放大和缩小,div 会保持在同一位置,因为它对叠加层是绝对的,如前所述。 然而问题就出在这里。您
我想找到 View 在显示屏幕上的位置。 为此,我使用了 view.getLeft() 、view.getBottom() 、view.getRight() 等方法> , view.getTop()。
我有一个看起来像这样的 View 层次结构(基于其他答案和 Apple 的使用 UIScrollView 的高级 AutoLayout 指南): ScrollView 所需的2 个步骤是: 为 Scr
所以我有一个名为 MARKS 的表,我有这些列 STUDENT_ID, CLASSFORM_NAME, ACADEMIC_YEAR, TERM, SUBJECT_NAME, TOTAL_MARKS
我有一个问题我无法理解,请帮助: 我开发了带有图像的 html 页面,并使用 jQuery UI 帮助使它们可拖动,我将这些图像位置设置为相对位置并给出了左侧和顶部像素,这是页面的链接 http://
我正在尝试创建一个 CSS 动画,它在 sprite 表中循环播放 16 个图像,给人一种幽灵“漂浮”的错觉。动画通过在 background-position 位置之间移动以显示不同状态的幽灵来实现
我正在创建这个网站的 WebView https://nearxt.com/打开时询问位置但是当我使用此链接在 flutter 中创建 webview 时那么它就无法定位我还在应用程序中定义了位置,但
我正在以编程方式创建一个需要跨越 2 个屏幕的窗口。正在创建的窗口的大小是正确的,但窗口大约从第一个屏幕的一半开始。我可以将它拖回第一个屏幕的开头,NSWindow 非常适合。 我只需要知道在窗口的起
位置“/”的匹配叶路由没有元素。这意味着默认情况下它将呈现一个空值,从而导致一个“空”页面 //App.js File import { BrowserRouter as Router, Routes
我有一个运行 Ubuntu 和 Apache 的 VPS 例如,假设地址是:5.5.5.5 在 VPS 上,我有一个名为 eggdrop 的用户(除了我的 root 用户)。 用户 eggdrop 有
我有一个 JLabel与 ImageIcon ,我使用 setIcon() JLabel中的函数. ImageIcon然后上来,坐在我的JLabel 的文字左侧.是否有可能拥有 ImageIcon在文
我的图中有节点,它们的 xlabels 位于它们的左上方。我怎样才能改变这个位置?我希望 xlabels 正好位于节点本身的旁边。 最佳答案 xlp是你想要的属性,但它没有做任何事情。 你不能改变位置
我对基本的 VIM 功能有疑问:(我尝试谷歌搜索但找不到答案) 如何列出所有自定义功能。(我做了 :function 并且不能找到我的自定义函数) 如何获得自定义函数列表中的函数(或它们的存储位置)。
我是 PHP 的新手,虽然我一直在搜索,但我不知道该怎么做。 我知道可以使用 Location("some page") 进行重定向。我还读到,只要没有向用户显示任何内容,它就可以工作。 我想做的是:
如果在 jgrowl.css 中位置更改为“center”,我如何将其覆盖为默认值,即“top-right” $.jGrowl(data, { header: 'data', an
我需要根据用户是否滑动屏幕顶部、屏幕中间或屏幕底部来触发不同的事件。我正在尝试找出最好/最简单的方法来做到这一点,因为我很确定没有办法从 UISwipeGestureRecognizer 获取位置。
我需要枚举用delphi编写的外部应用程序中使用的类 ,因此我需要访问VMT表以获取该信息,但是我找不到任何有关如何在exe(由delphi生成)文件中找到VMT(虚拟方法表)的位置(地址)的文档。
在 D2010 (unicode) 中是否有像 Pos 这样不区分大小写的类似函数? 我知道我可以使用 Pos(AnsiUpperCase(FindString), AnsiUpperCase(Sou
我正在尝试为我的reveal.js 演示文稿制作一个标题,该标题会粘贴在屏幕顶部。标题中的内容在每张幻灯片的基础上都是动态的,因此我必须将标记放在 section 标记中。 显然,如果标记在 sect
我是一名优秀的程序员,十分优秀!