自定义微调器和从右到左的语言:模拟器上的输出问题 [英] Custom spinner and right to left language: problem with output on emulator
本文介绍了自定义微调器和从右到左的语言:模拟器上的输出问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些,但在运行程序后,我在仿真器上看不到任何输出。
I have these, but after running the program, I do not see any output on emulator.
MySpinnerAdapter.cs
namespace spinnerTest
{
public class MySpinnerAdapter : ArrayAdapter<String>
{
Typeface font = Typeface.CreateFromAsset(Application.Context.Assets, "fonts/MYFONT.TTF");
public MySpinnerAdapter(Context context, int resource, String[] items)
: base(context, resource, items)
{
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
TextView view = (TextView)GetView(position, convertView, parent);
view.SetTypeface(font, TypefaceStyle.Normal);
return view;
}
public override View GetDropDownView(int position, View convertView, ViewGroup parent)
{
TextView view = (TextView)GetDropDownView(position, convertView, parent);
view.SetTypeface(font, TypefaceStyle.Normal);
return view;
}
}
}
textview_with_padding
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerItemStyle"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee" />
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Spinner
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.cs
namespace spinnerTest
{
[Activity(Label = "spinnerTest", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
String[] spinnerItems = new String[]{
"Aa",
"Bbb",
"Cccc",
"Ddddd",
"Ee",
};
Spinner SpinnerWithPadding = (Spinner)FindViewById(Resource.Id.spinner2);
ArrayAdapter<String> spinnerArrayAdapter = new MySpinnerAdapter(this, Resource.Layout.textview_with_padding, spinnerItems);
spinnerArrayAdapter.SetDropDownViewResource(Resource.Layout.textview_with_padding);
SpinnerWithPadding.Adapter = spinnerArrayAdapter;
}
}
}
我尝试了什么:
我没有任何错误,但我在模拟器上没有输出。
What I have tried:
I do not have any error but I do not have output on Emulator.
推荐答案
我发现:
我的问题出现在MySpinnerAdapter.cs中:
我没有使用基础GetView(base.GetView)和GetDropDownView(base.GetDropDownView)。
I found:
My problem was in MySpinnerAdapter.cs:
I had not used base for GetView (base.GetView) and GetDropDownView (base.GetDropDownView).
TextView view = (TextView)base.GetView(position, convertView, parent);
TextView view = (TextView)base.GetDropDownView(position, convertView, parent);
这篇关于自定义微调器和从右到左的语言:模拟器上的输出问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文