我知道关于'getView几次调用'这个问题的问题很少,但我的问题却没什么不同.
我有一个自定义listView与自定义行(使用row_layout.xml).它通常运作良好.一开始我遇到了多次调用getView的问题,并且使用我在stackoverflow中看到的方法之一修复了它.(使用'usedPositions'数组).
现在,我在日志中看到这个场景:getView pos 0,getView pos 1,getView pos 0,getView pos 1.这导致我的行加倍.只有当我调用覆盖当前活动的新活动然后关闭该活动时才会发生这种情况.(例如,打开相机活动,然后关闭它).
我将展示我的代码:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
Toast toast = Toast.makeText(this.context, "getView " + position, 1000);
toast.show();
String pos = Integer.toString(position);
if (!usedPositions.contains(pos)) {
CardHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CardHolder();
//holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtCouponTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.txtBusinessName = (TextView)row.findViewById(R.id.txtBusinessName);
row.setTag(holder);
}
else …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,该应用程序应该检测 nfc 标签并自动启动。我已经通过使用 TECH_DISCOVERED + 过滤器成功做到了这一点,但我认为更好的方法是使用 NDEF_DISCOVERED。我已将意图过滤器添加到我的清单中,但它不起作用。这是我的 TECH_DISCOVERED 清单代码,有效:
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED"/>
</intent-filter>
<meta-data android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
Run Code Online (Sandbox Code Playgroud)
当我想尝试 NDEF_DISCOVERED 时,我尝试:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
Run Code Online (Sandbox Code Playgroud)
对于标签,我使用“Mifare classic 1k”标签,该标签使用市场上的 NFC TagInfo 应用程序编写为“智能海报”。
我究竟做错了什么?或者,还有什么方法可以启动我的应用程序而不显示活动选择对话框?
谢谢,埃兰。