我有一个设置了ArrayAdapter的ListView,并且适配器中的每一行都包含四个需要接收和处理点击事件的按钮.通常在Android中,我会SetOnClickListener在创建单元格时调用每个按钮,但Mono可以为事件设置事件处理程序Click.看起来在Mono中有一些奇怪的东西,因为我遇到了两个问题之一,这取决于我设置事件处理程序的位置.
ArrayAdapter GetView示例1:
View tweetCell = convertView;
if (tweetCell == null) {
tweetCell = ((LayoutInflater)Context.GetSystemService (Context.LayoutInflaterService)).Inflate (Resource.Layout.TweetCell, null);
tweetCell.FindViewById (Resource.Id.btn_moveTweet).Click += (object sender, EventArgs e) => MoveTweet (GetItem(position));
tweetCell.FindViewById (Resource.Id.btn_unfavoriteTweet).Click += (object sender, EventArgs e) => UnfavoriteTweet (GetItem(position));
tweetCell.FindViewById (Resource.Id.btn_hideTweet).Click += (object sender, EventArgs e) => HideTweet (GetItem(position));
tweetCell.FindViewById (Resource.Id.btn_shareTweet).Click += (object sender, EventArgs e) => ShareTweet (GetItem(position));
}
Run Code Online (Sandbox Code Playgroud)
在这里,我的事件处理程序每个按钮只设置一次(好!),但position大多数时候该值都是错误的.我想知道从Mono到Android代码的转换是否导致每次GetItem(position)使用相同的值position(position首次创建单元格时设置的值).这段代码在普通Android中完全正常.
ArrayAdapter GetView示例2:
View tweetCell = convertView;
if (tweetCell …Run Code Online (Sandbox Code Playgroud) 我一直在努力更换股票的汽车之家应用程序,我完全不知道如何覆盖主页按钮,这样我的应用程序将在手机停靠时返回到前台.这是Car Home的工作方式,所以必须有办法.
似乎BroadcastReceivers不起作用,因为每当按下Home按钮时广播的意图仍然会导致默认的主屏幕应用程序启动; 我无法阻止它.我可以从我的应用程序中覆盖主页按钮,但这对我没有好处,因为当用户在我的应用程序之外时,这需要工作.Car Home也没有做任何奇怪的事情,比如在运行时将自己设置为默认的主屏幕应用程序(我检查了logcat以确保).
在这方面,我一直在撞墙.有没有人有任何想法,或者你能否至少指出我正确的方向?
我正在构建一个使用一些主题进行活动的应用程序.他们都在运行Android前ICS版本的手机上工作得很好,但出于某种原因,当我在Galaxy Nexus(运行4.1)和Nexus S(运行4.0.4)上应用主题时,背景总是黑色的.
这是我正在使用的一个不起作用的主题:
<style name="BlueStyle" parent="@android:style/Theme.Holo.NoActionBar">
<item name="android:background">@color/Blue</item>
<item name="android:textColor">@android:color/white</item>
<item name="android:textSize">16dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)
蓝色在我的定义中定义res/values/colors.xml.主题res/values-v11/styles.xml在我的清单中并在其中引用,如下所示:
<activity
android:name=".activity.SplashActivity"
android:theme="@style/BlueStyle"
android:configChanges="orientation|keyboardHidden|screenSize"/>
Run Code Online (Sandbox Code Playgroud)
就像我说的那样,一个类似的主题(在下面res/values,@android:style/Theme.NoTitleBar作为父母使用)适用于Android前ICS版本中的同一个Activity.即使我进入布局文件并制作布局的背景,@color/Blue如果我将主题分配给活动,它仍然是黑色的.但是,我发现,如果我将主题设置为,@android:style/Theme.NoTitleBar那么Activity将使用我在布局文件中强制使用的蓝色.
我也尝试将BlueStyle设置为整个应用程序的主题,但它没有任何区别.
以前有人遇到过这个问题吗?这是我第一次尝试支持pre-v11和v11 +主题,所以我可能会犯一些非常明显的错误.
编辑:还忘了提到我的活动开始时我确实看到了一瞬间的蓝色,但随后背景变黑了.不确定该信息是否有帮助.
编辑#2:我刚刚在运行3.2的Galaxy Tab 10.1上进行了测试,它也有问题.
android themes styles android-layout android-4.0-ice-cream-sandwich