我试图让一个完全自定义的微调。我正在与制作弹出,当你$它p $ PSS布局的困难。这是我的$ C $下我的适配器:
I am trying to make a fully custom spinner. I am running into difficulties with making the layout that pops up when you press on it. Here is my code for my adapter:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.my_array, R.layout.spinnertext);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
这是我看过的文档中,使用的布局apears由该行进行设置:
From what I have read in the documentation, the layout used apears to be set by the line:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
虽然每次我将其更改为一个新的布局我做,这让当我尝试使用微调应用程序失败。我试图寻找什么是android.R.simple_spinner_dropdown_item的模样,以便弄清楚,如果我也许错过什么。
Although every time I change it to a new layout that I make, it makes the app fail when I try and use the spinner. I have tried to look for what "android.R.simple_spinner_dropdown_item" looks like so as to figure out if I am maybe missing anything.
我所有的布局,我曾尝试过的线性或相对布局,只有一个TextView。
All of my layouts I have tried have been linear or relative layouts, with only a textView.
我怎样才能让一个自定义布局弹出时,选择了微调?
How can I make a custom layout pop up when the spinner is selected?
推荐答案
row.xml设置各行的布局(在这种情况下:一个图像和文本的每一行):
row.xml to set up the layout on each row (in this case: one image and text each row):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView
android:id="@+id/weekofday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Java的:
Java:
public class AndroidCustomSpinner extends Activity {
String[] DayOfWeek = {"Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner mySpinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row, R.id.weekofday, DayOfWeek);
mySpinner.setAdapter(adapter);
}
}
相关推荐
最新文章